[英]how to add the content of the cell of table view in other view when clicked on cell in objective-c
[英]How to generate a second table view when the user touches a cell in the first (dynamic) table view (in Objective-C)?
我有一個表格視圖,其中包含在 class TableViewController 中生成的動態單元格。 我轉至另一個表視圖(繼承自 TableViewController2)。 當用戶從第一個表視圖中選擇一個單元格時,我想觸發新表視圖的顯示。 我在 TableViewController 中實現了 prepareForSegue。 segue 有效,我可以看到第一個表視圖彈出屏幕,新的表視圖彈出,但無論我做什么,它都是空的。 如何觸發 TableViewController2 中單元格的顯示?
在表視圖控制器中:
-(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;
}
}
在 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;
}
您是否在第二個tvc中定義了以下兩個方法?
和
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.