-(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;
}