我有一個表格視圖,其中我可以添加1或減去1到我的cell.textLabel.text
的值,但是當我切換視圖並返回或滾動單元格視圖,當它回到視圖中時,textLabel
的值返回到1
這是最初的起點!請幫忙!這裏是加1和減1的代碼:當單元格滾動出視圖時,TableViewCell的textLabel值返回到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];
}
}
好的,我接受了你的建議,並加入了這個:' - (IBAction)addLabelText:(id)sender {0} { num = [NSString stringWithFormat:@「%d」,[cell.textLabel.text intValue] +1]; [number addObject:num]; [myTableView reloadData]; }' 可以工作嗎?它增加了罰款,但我不能得到它減去工作!感謝您的幫助+1 – iProRage 2012-01-12 00:30:22
不!您的初始代碼(即您問題中的代碼)可以工作。 假設我們已經使Cell標識符唯一,只需在兩個方法的末尾添加[myTableView reloadData]即可。 它應該工作。祝你好運。 – nomann 2012-01-12 12:53:52
alirght會做,再次感謝! :d – iProRage 2012-01-12 23:45:00