【发布时间】:2017-08-30 17:50:05
【问题描述】:
在UIViewController 1,我设置了一个数组。这个UIViewController 转为UIViewController 2。
在UIViewController 2 中,有一个带有自定义UITableViewCell 的UITableView。还有一个UIButton 可以很好地返回UIViewController 1。
在自定义单元格中,有一个collectionView。这是由来自ViewController 1 的数组填充的。
我的问题是,当在collectionView(UIViewController 2 - 自定义UITableViewCell 类)中选择一个项目时,如何将该值一直传递回UIViewController 1?
如果这是重复的,我很抱歉。我在这里提到了许多类似的条目,但似乎没有任何效果。我也试过这个:
http://www.appcoda.com/ios-collection-view-tutorial/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showRecipePhoto"]) {
NSArray *indexPaths = [self.collectionView indexPathsForSelectedItems];
RecipeViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [indexPaths objectAtIndex:0];
destViewController.recipeImageName = [recipeImages[indexPath.section] objectAtIndex:indexPath.row];
[self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
}
我不断收到返回的空值,但我不知道为什么。
(我没有使用故事板。这是我第一次尝试任何类型的编程。希望有任何意见!)
【问题讨论】:
标签: ios objective-c uitableview uicollectionview