【发布时间】:2012-01-11 04:33:55
【问题描述】:
我有一个表格视图,我可以在其中将我的 cell.textLabel.text 的值加 1 或减 1,但是当我切换视图并返回或滚动一个单元格时,当它返回到视图中时, textLabel 的值返回到 1 原来的起点!请帮忙!下面是加减1的代码:
- (IBAction)addLabelText:(id)sender{
cell = (UITableViewCell*)[sender superview]; // <-- ADD THIS LINE
cell.textLabel.text = [NSString stringWithFormat:@"%d",[cell.textLabel.text
intValue] +1];
}
- (IBAction)subtractLabelText:(id)sender
{
cell = (UITableViewCell *)[sender superview];
if ( [[cell.textLabel text] intValue] == 0){
cell.textLabel.text = [NSString stringWithFormat:@"%d",[cell.textLabel.text intValue] +0];
}
else{
cell.textLabel.text = [NSString stringWithFormat:@"%d",[cell.textLabel.text intValue] -1];
}
}
【问题讨论】:
标签: iphone ios ipad uitableview ipod