简体   繁体   English

当用户触摸第一个(动态)表视图(在 Objective-C 中)中的单元格时,如何生成第二个表视图?

[英]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中定义了以下两个方法?

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

and

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在objective-c中单击单元格时如何在其他视图中添加表视图单元格的内容 - how to add the content of the cell of table view in other view when clicked on cell in objective-c 我如何将第二行放在Objective-C的表格视图单元格中? - how can i put the second line in the table view cell in objective-c? 表单元未出现在表视图objective-C中 - table cell not appear in table view objective-C 目标C:如何在加载视图时突出显示表视图中的第一个单元格? - Objective C: How to highlight the first cell in table view when view loads? 在objective-c的表视图的每个单元格中获得相同的值 - getting the same value in each cell of table view in objective-c 如何在Objective-C中使用Segue表视图控制器单元格单击和单元格长按 - how to use segue table view controller cell click and cell long click in Objective-C 突出显示表格视图单元格不会使用Objective-C突出显示表格视图单元格的子视图 - Highlighting table view cell will not highlight subviews of table view cell using objective-C 没有数据显示时,Objective-C删除表视图 - Objective-c remove table view when no data present to show 当我单击第一个表格视图的表格视图单元格时进入第二个表格视图? - Going into a second table view when i click on a table view cell of a first table view? 如何在 Objective-C (iPhone) 的表格视图中使用两个不同的动态单元格? - How to use two different dynamic cells with a Table view in Objective-C (iPhone)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM