0
我有一个Master-Detail tableview,并希望根据正在显示的对象的属性将用户带到不同的Detail VC。IOS:使用tableview,如何访问didSelectRowAtIndexPath中的数据对象
例如,如果演员在电影中,我想要转到电影视图控制器,但是如果演员在电视节目中,则为电视节目优化的视图控制器。
我已经将细节VC连接到视图控制器,而不是表视图,因此使用didSelectRowAtIndexPath,我可以使用逻辑和执行Segue将用户发送到不同的细节VC。
但是,实现逻辑所需的信息位于cellforrowatindexpath中的数据对象中。所以我的问题是如何将此信息传递给didSelectRow,或者将segue的逻辑放置在cellforrowatindexpath中。
感谢您的任何建议。
这里是我当前的代码:
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
UITableViewCell *theCellClicked = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *segueName = nil;
if ([_credit.type isEqual: @"movie"]) {
segueName = @"goToMovie";
}
else if ([_credit.type isEqual: @"television"]) {
segueName = @"goToTVShow";
}
[self performSegueWithIdentifier: segueName sender: self];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Credit *credit = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
cell.textLabel.text = credit.name;
return cell;
}