【问题标题】:How to call/pass an array value from a table cell into a view?如何将数组值从表格单元格调用/传递到视图中?
【发布时间】:2012-02-15 22:08:13
【问题描述】:
作为 iOS 的新手/初学者程序员,不幸的是,我遇到了一个障碍,我需要一些帮助。使用故事板,我创建了一个具有单个原型单元格的表格视图。然后,该单元格将填充从数组(两个标签,titleLabel 和 timeLabel,以及由整数 typeOfCell 表示的单元格的“类型”)传递的信息,从而允许由数组生成多个单元格,而仅使用单个原型单元“模板”。 我想要完成的是允许用户从表格中选择一个单元格,然后出现一个显示该单元格中信息的视图。由于我是初学者,请明确说明您应该选择回答这个问题的说明。非常感谢任何反馈,感谢您的时间和回答。
【问题讨论】:
标签:
iphone
ios
uitableview
nsmutablearray
【解决方案2】:
如果您正在考虑将值从tablecell传递到被调用的视图,那么您可以在视图中创建与要传递的值对应的成员变量,合成它并在didSelectRow方法中传递值.
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CustomTableCell *lCell = (CustomTableCell*)[tableView cellForRowAtIndexPath:indexPath];
if(indexPath.row == x) //x being the row required
{
NewViewController *lNewVC = [[NewViewController alloc] init]; //This class will have titleLabel, timeLabel and cellType as member vars
lNewVC.titleLabel = cell.titleLabel;
lNewVC.timeLabel = cell.timeLabel;
lNewVC.cellType = cell.typeOfCell;
[self.navigationController pushViewController:lNewVC animated:YES];
}
else
/* similar code for other rows */
}