【发布时间】:2015-04-16 16:17:27
【问题描述】:
我是 IOS 新手,我刚刚在 UITableView 工作。我想从两个不同的视图控制器中填充表视图中的数据。我想从视图控制器更新cell.textLabel.text,比如viewController1,从另一个视图控制器更新cell.detailTextLabel.text,比如viewController2。
我在tableView 的右上角有一个条形按钮,单击它可以导航到视图控制器 A。我在视图控制器 A 中有一个文本标签,它会将用户输入到 tableView 的内容返回。
当我单击单元格时,它会导航到 View Controller B。我在 View Controller B 中也有一个文本标签。
这是我的tableView 数据源方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Names *namesToDisplay = [self.lists objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = namesToDisplay.firstName;
return cell;
}
其中Names 是NSObject 的模型类,列表是tableView 中的NSArray。
如果我从单个视图控制器(视图控制器 1 或视图控制器 2)更新 cell.textlabel.text 和 cell.detailtextlable.text 效果很好。
我可以从 viewController2 获取数据,但我应该在哪里获取 cell.detailTextLabel.text ?
【问题讨论】:
-
你现在解决这个问题了吗?答案有帮助吗?如果不是,请发表评论,如果是,请投票/接受;)
标签: ios objective-c uitableview tableviewcell