iOS 编辑页面的实现方法,从一个页面跳转(push)到下一页面时怎么传递数据

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //这是一个包含text属性的模型
    PGAddText *model = self.data[indexPath.row];
    //创建第二个控制器
    PGAddTextViewController *text = [[PGAddTextViewController alloc]init]; 
    //打算设置第二个页面的textView的text属性
    text.textView.text = model.text;
    [self.navigationController pushViewController:text animated:YES];
}

这是页面一原本写的代码,打算设置第二个页面的textView的text属性,但是没有成功。第二个页面什么也没有显示。

总结原因应该是第二个页面在viewDidLoad的时候已经生成好了,所以修改没有起作用。所以直接传模型数据,在第二个页面的viewDidLoad的时候自己加载设置数据。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //这是一个包含text属性的模型
    PGAddText *model = self.data[indexPath.row];
    //创建第二个控制器
    PGAddTextViewController *text = [[PGAddTextViewController alloc]init]; 
    //直接传模型数据,在第二个页面的viewDidLoad的时候自己加载设置数据        
    text.data = model;
    [self.navigationController pushViewController:text animated:YES];
}

第二个页面的viewDidLoad方法

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置数据
    self.textView.text = self.data.text;

}
posted @ 2015-12-16 03:28  嘣嚓嚓  阅读(2083)  评论(0编辑  收藏  举报