正如我在评论中所说,我认为当前的设计不是满足要求的最佳选择,但如果除了将数据基本上存储在单元格的标签中之外,绝对没有其他方法可以做到这一点,我会这样做:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)ip
{
/* instantiate cell here */
NSString *cellText = /* however you need to get the cell text */;
cellText = [cellText stringByReplacingOccurrencesOfString:@"_" withString:@" "];
cell.textLabel.text = cellText;
/* whatever other cell setup you need */
}
然后在选择回调中:
- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip
{
UITableViewCell *cell = [tv cellForRowAtIndexPath:ip];
NSString *cellText = cell.textLabel.text;
cellText = [cellText stringByReplacingOccurrencesOfString:@" " withString:@"_"];
/* go do whatever with cellText */
}
希望这可以帮助。