您的位置:首页 > 移动开发 > IOS开发

iOS开发中的一些tips

2015-06-24 09:55 477 查看
6/24/15

1.去除tableView底下空白行:self.tableView.tableFooterView = [[UIView alloc]init];还可以把分割线去了看起来效果差不多,self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone

2.今天遇到的坑,建立tableViewCell子类后对调用layoutSubviews对cell进行重新布局,以及重新调整row height后分割线的位置竟然插在cell中间,原来是调用layoutSubviews的时候没有调用[super layoutSubviews],所以这个很重要。

3.UITableView的结构和UICollectionView应该差不多,这是我猜的,我还没去看官方文件,之所以这么猜测是在用代码向cell添加subview的时候要加在cell.contentView上,这和collectionView一样。UICollectionViewCell自内向外的顺序是backgroundView、selectedBackgroundView、contentView。

6/25/15

1.tableViewCell是重用模式,所以直接从Cell中读取数据是不可取的模式,严格遵守MVC吧。

2.在用NSUserDefaults做数据存储的时候被初始化坑了,我是在viewDidLoad中做的初始化,所以每次推出重新开始就像没做数据存储一样,终于明白下面写法的重要性。。。

NSArray *array = [[NSUserDefaults standardUserDefaults]arrayForKey:COLLECT];
if(array == nil){
NSMutableArray *carray = [NSMutableArray array];
for(int i = 0; i<25; i++){
[carray addObject:@"NO"];
}
[[NSUserDefaults standardUserDefaults] setObject:[carray copy] forKey:COLLECT];
[[NSUserDefaults standardUserDefaults] synchronize];
}


就是先读取,没有的话才创建。

3.在viewController中调用AppDelegate

-(AppDelegate *)appdelegate{
return [[UIApplication sharedApplication]delegate];
}


7/28/15

1.属性关系有两种类型:strong和weak,相当于非ARC环境中的retain和assign

2.申明delegate要用weak

3.不要调用[super dealloc]

10/8/15



但是这个设置同时也会改变tabbar的title设,所以应该使用

self.navigationItem.title
= @"sth";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: