【发布时间】:2015-08-02 21:30:23
【问题描述】:
我正在尝试为我当前正在构建的应用程序的一部分创建清单,但我无法使用viewWithTag: 更新原型单元格上的文本。应用程序中的其他所有内容都正常工作,我可以单击正在创建的单元格。
需要使用 viewWithTag 的两种方法是:
- (void)configureCheckmarkForCell:(UITableViewCell *)cell withChecklistItem:(OTChecklistItem *)item {
UILabel *label = (UILabel *)[cell viewWithTag:1001];
if (item.checked) {
label.text = @"√";
} else {
label.text = @"";
}
label.textColor = self.view.tintColor; }
和
- (void)configureTextForCell:(UITableViewCell *)cell withChecklistItem:(OTChecklistItem *)item
{
UILabel *label = (UILabel *)[cell viewWithTag:1000];
label.text = item.itemName;
}
这些方法被调用:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Get a new or recycled cell
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"OTChecklistTableViewCell" forIndexPath:indexPath];
NSArray *items = [[OTChecklistStore sharedStore] allItems];
OTChecklistItem *item = [items objectAtIndex:indexPath.row];
[self configureTextForCell:cell withChecklistItem:item];
[self configureCheckmarkForCell:cell withChecklistItem:item];
return cell;
}
这是我的故事板中的一些屏幕截图,显示我的连接和标签应该是正确的。
【问题讨论】:
-
你的保存方法是空的!! - (void)save:(id)sender { [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; } 只会关闭视图!
-
对象已经被创建,所以除了关闭视图之外我不需要做任何事情。从表格中创建新对象后,您可以尝试单击单元格,您保存的数据将显示在 detailViewController 中。
-
不要在您的项目中发布墨迹。使用相关详细信息/代码更新您的问题。
标签: ios objective-c uitableview cocoa-touch