我似乎無法弄清楚如何做到這一點,希望這裏有人能幫助我。在我的tableview中,我想將複選框添加到每個單元格,如果觸摸該複選框,則會出現複選標記,並且應該發生特定操作。但如果你只是觸摸細胞,就會發生不同的動作。有沒有人有一個想法如何做到這一點?我開始做以下事情。但我認爲我的方法會造成內存泄漏,而且我不知道如何執行僅針對所有按鈕的按鈕的動作..... 如果有人能幫我解決問題,那將會很棒......iphone:如何將複選框添加到uitableviewcell?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *tempArray = [[exerciseNames objectAtIndex:indexPath.section] objectForKey:@"rowValues"];
UIButton *checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
checkButton.tag = indexPath.row;
[checkButton setFrame:CGRectMake(10, 10, 23, 23)];
if (checkButtonPressed == YES) {
[checkButton setBackgroundImage:[[UIImage imageNamed:@"checked.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
}
else {
[checkButton setBackgroundImage:[[UIImage imageNamed:@"unchecked.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
}
[checkButton addTarget:self action:@selector(checkAction) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:checkButton];
cell.imageView.image = [UIImage imageNamed:@"unchecked.png"];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", [[tempArray objectAtIndex:indexPath.row] objectForKey:@"full"], [[tempArray objectAtIndex:indexPath.row] objectForKey:@"short"]];
// Set up the cell...
return cell;
}
這個問題問的附加複選框在表格單元格,不會添加到UITableViewCellAccessoryCheckmark – NANNAV 2012-10-03 08:56:17