我有一个视图控制器,它以模态的方式呈现,并在模态的父视图控制器(表视图)中更改一些影响uitableview中的数据的数据。
当父视图重新出现时,我调用tableview的reloadData方法。我已经确认这段代码会受到一个断点的攻击。我的问题是,reloadData不工作。这里有一个要点--如果我没有在- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中使用reuseIdentifiers,数据就会正确地重新加载。看起来reuseIdentifier是罪魁祸首。
我真的想继续在我的单元中使用reuseIdentifier --我该怎么做呢?
发布于 2010-03-24 13:08:14
这个问题不太可能与重用标识符有关。请发布您的tableView:cellForRowAtIndexPath:方法的代码。
发布于 2010-03-24 13:24:09
我明白了,你是对的,不是reuseIdentifer。
我将内容分配嵌套在单元分配的正下方,如下所示:
// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = [targetRow.children count] ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
// Configure the cell.
cell.textLabel.text = [NSString stringWithFormat: targetRow.title];
}因为找到了出列的单元,所以内容不会被更新。
我把它改成这样,现在一切都好用了……
// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType = [targetRow.children count] ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
// Configure the cell.
cell.textLabel.text = [NSString stringWithFormat: targetRow.title];https://stackoverflow.com/questions/2505416
复制相似问题