我以编程方式创建了一个 UITableView,其中包含连接到情节提要中其他视图的不同单元格和部分
我想连接我的单元格,我的意思是当用户选择特定行时它应该进入新视图“你可以在故事板视图中看到它们是如何相互连接的”
我的问题是:
如何将这些单元格连接到我为 prepareForSegue:,viewDidLoad,didSelectRowAtIndexPath: 编写代码的视图,并且我知道我应该在 cellForRowAtIndexPath: 方法中编写连接代码,但我不知道该怎么写,请你帮忙我
提前致谢!
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
[[cell textLabel] setText:contentForThisRow];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedIndex = indexPath.row;
[self.tableView reloadData];
}