【发布时间】:2015-05-10 07:21:46
【问题描述】:
我在使用 SWRevealViewController 时遇到问题。如何在 didSelectRowAtIndexPath 中调用为 segue 做准备?这是必要的,因为在 tableView 我有类别的名称,其中一些类别有自己的子类别。例如我的清单:
- category1
- category2
+ category3
- category4
所以,当我点击 + category3 时,我应该会看到
- category1
- category2
+ category3
- subcategory1
- subcategory2
- category4
但是因为 prepareForSegue 我不能这样做 这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section <= _categories.count) {
GDCategory *category = [[_subCategories objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
_gdCategory = category;
if (category.subcategories.count > 0) {
NSNumber *categoryId = @(category.dbId);
if ([_selectedSubCategories containsObject:categoryId]) {
[_selectedSubCategories removeObject:categoryId];
} else {
[_selectedSubCategories addObject:categoryId];
}
NSLog(@"There are %lu subcategories in %@", (unsigned long)category.subcategories.count, category.name);
[self recalcSubcategories];
[tableView reloadData];
} else {
//Here I should call prepareForSegue
}
NSLog(@"selected category is %@", category.name);
}
}
- (void)prepareForSegue: (UIStoryboardSegue *)segue sender:(id)sender {
// configure the destination view controller:
if ( [sender isKindOfClass:[UITableViewCell class]] ) {
UINavigationController *navController = segue.destinationViewController;
GDCategoryVC *categoryVC = [navController childViewControllers].firstObject;
if ( [categoryVC isKindOfClass:[GDCategoryVC class]] ) {
categoryVC.selectedCategory = _gdCategory;
}
}
}
另外,我不能传递数据 throw VC,因为 prepareForSegue 首先调用。请帮我。谢谢!
【问题讨论】:
标签: ios uitableview uistoryboardsegue didselectrowatindexpath swrevealviewcontroller