테이블 뷰를 사용하여 1을 더하거나 1을 뺍니다. cell.textLabel.text
의 값으로 1을 뺍니다. 그러나 뷰를 전환하고 셀을 반환하거나 스크롤 할 때 보기로 돌아 오면 다시 textLabel
의 값이 원래 출발점 인 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) 보낸 사람 { cell = (UITableViewCell *) [보낸 사람 수퍼 뷰]; num = [NSString stringWithFormat : @ "% d", [cell.textLabel.text intValue] +1]; [number addObject : num]; [myTableView reloadData]; } 이 방법을 사용할 수 있습니까? 괜찮아요,하지만 빼고 일할 수는 없어요! 도와 줘서 고마워 +1 – iProRage
아니! 초기 코드 (예 : 질문의 코드)가 작동합니다. 셀 식별자를 고유하게 만들었다 고 가정하면 두 메서드의 끝에 [myTableView reloadData]를 추가하면됩니다. 그리고 작동합니다. 행운을 빌어 요. – nomann
alirght, 다시 한 번 감사드립니다! :디 – iProRage