[英]How to generate a second table view when the user touches a cell in the first (dynamic) table view (in Objective-C)?
I have a table view with dynamic cells generated in the class TableViewController.我有一个表格视图,其中包含在 class TableViewController 中生成的动态单元格。 I made a segue to another table view (which inherits from TableViewController2).
我转至另一个表视图(继承自 TableViewController2)。 I want to trigger the display of the new table view when the user selects a cell from the first table view.
当用户从第一个表视图中选择一个单元格时,我想触发新表视图的显示。 I implemented prepareForSegue in TableViewController.
我在 TableViewController 中实现了 prepareForSegue。 The segue works, I can see the first table view pop off screen and the new table view pop in, but it's empty whatever I do.
segue 有效,我可以看到第一个表视图弹出屏幕,新的表视图弹出,但无论我做什么,它都是空的。 How can I trigger the display of the cells in TableViewController2?
如何触发 TableViewController2 中单元格的显示?
In TableViewController:在表视图控制器中:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
if ([(segue.identifier) isEqualToString:@"topSegue"]){
TableViewController2 *navigationController = segue.destinationViewController;
TableViewController2 *tvc = segue.destinationViewController;
}
}
In TableViewController2:在 TableViewController2 中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Top 50 list";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"test";
return cell;
}
Did you define the following two methods in your second tvc?您是否在第二个tvc中定义了以下两个方法?
and和
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.