在push到下一个controller的时候,应注意以下几点:
1》在执行push代码的时候,才创建controller,不要在push之前使用controller里面的view
如下面的错误事例:
CommentModel *model = [_arraySaveDataobjectAtIndex:but.tag];
CommentDetailViewController *commentDetailVC = [[CommentDetailViewControlleralloc] init];
commentDetailVC.navigationItem.title = but.titleLabel.text;
NSData *imageData = [NSDatadataWithContentsOfURL:getImageUrl(model.filename)];
commentDetailVC.imageView.image = [UIImage imageWithData:imageData];
commentDetailVC.lable.text = model.goods_name;
commentDetailVC.ID = model.ID;
commentDetailVC.goods_id = model.goods_id;
commentDetailVC.order_id = model.order_id;
[self.navigationControllerpushViewController:commentDetailVC animated:YES];
注:标红的两句是错误的,这样会造成传过去的数据为空,因为在push之前还没创建controller
应修改为:
commentDetailVC.image = [UIImage imageWithData:imageData];
commentDetailVC.text = model.goods_name; 【不使用push到的那个controller的视图相关的内容】
UINavigationController在一个界面push到另一个界面传数据时的注意点,布布扣,bubuko.com
UINavigationController在一个界面push到另一个界面传数据时的注意点
原文地址:http://www.cnblogs.com/yuanyuandachao/p/3784391.html