cell.textLabel.text
에서 1
을 더하고 빼면됩니다. 나는이 방법으로 1을 더하고있다 :cell.textLabel.text에 1을 빼면 앱이 손상됩니다.
- (IBAction)addLabelText:(id)sender{
num = [NSString stringWithFormat:@"%d",[cell.textLabel.text intValue] +1];
number = [[NSMutableArray alloc]initWithObjects:num, nil];
[myTableView reloadData];
}
그리고 나는 빼기 위해 textLabel을 얻는다! 여기 내 방법 : 내 cellForRowAtIndexPath
방법에서
- (IBAction)subtractLabelText:(id)sender
{
if ([[cell.textLabel text] intValue] == 0){
num = [NSString stringWithFormat:@"%d",[num intValue] +0];
[number addObject:num];
}
else{
num = [NSString stringWithFormat:@"%d",[num intValue] -1];
[number addObject:num];
}
}
, 나는이 라인 레이블의 텍스트를 설정하려고 :
cell.textLabel.text = [number objectAtIndex:indexPath.row];
+ 버튼을 작동하지만, - 버튼을 나던. 내가 어떻게 고칠 수 있니? 미리 감사드립니다!
CELLFORROW
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
addBtn = [[UIButton alloc]init];
addBtn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[addBtn setFrame:CGRectMake(220,10,25,55)];
[addBtn addTarget:self action:@selector(addLabelText:) forControlEvents:UIControlEventTouchUpInside];
[addBtn setTitle:@"+" forState:UIControlStateNormal];
[addBtn setEnabled:YES];
[cell addSubview:addBtn];
subBtn = [[UIButton alloc]init];
subBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[subBtn setFrame:CGRectMake(260,10,25,55)];
[subBtn addTarget:self action:@selector(subtractLabelText:) forControlEvents:UIControlEventTouchUpInside];
[subBtn setTitle:@"-" forState:UIControlStateNormal];
[subBtn setEnabled:YES];
[cell addSubview:subBtn];
//cell.textLabel.text = @"1";
}
//cellText.hidden=!self.editing;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.imageView.image = [imageArray objectAtIndex:indexPath.row];
cell.textLabel.text = [number objectAtIndex:indexPath.row];
return cell;
}
CRASH 로그는 어디에 있습니까? 그것을 게시하십시오. 앱 크래시가 발생하면 먼저 크래시 로그를 찾습니다. – 0x8badf00d
cellForRowAtIndexPath 메소드를 볼 수 있습니까? 또한이 프로젝트에 ARC를 사용하고 있습니까? – UIAdam
@ Adam @ ARC 란 무엇입니까? 그리고 예, 아쉽게 행과 크래시 로그에 셀을 게시하십시오! – iProRage