3
我有一個複選框,當它被選中時,它會被複選標記。但是當我選擇單元格時,高亮顯示覆選框。對不起,我可怕的英語,但這裏是下面的代碼。有沒有一種方法讓我在高亮上勾上覆選標記按鈕?UITableViewCell突出顯示涵蓋我的附件查看
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
if([tableView isEqual:self.myTableView]){
static NSString *TableViewIdentifier = @"MyCells";
cell = [tableView dequeueReusableCellWithIdentifier:TableViewIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableViewIdentifier];
}
//configure the cell
checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect checkboxRect = CGRectMake(135, 150, 36, 36);
[checkbox setFrame:checkboxRect];
[checkbox setImage:[UIImage imageNamed:@"[email protected]"]forState:UIControlStateNormal];
[checkbox setImage:[UIImage imageNamed:@"[email protected]"] forState:UIControlStateSelected];
[checkbox addTarget:self action:@selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = checkbox;
NSString *group;
NSUInteger row = [indexPath row];
switch (indexPath.section) {
case 0:
group = [suggestedPeople objectAtIndex:row];
cell.textLabel.text = group;
break;
case 1:
group = [aArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 2:
group = [bArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 3:
group = [cArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 4:
group = [dArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 5:
group = [eArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 6:
group = [fArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 7:
group = [gArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 8:
group = [hArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 9:
group = [iArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 10:
group = [jArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 11:
group = [kArray objectAtIndex:row];
cell.textLabel.text = group;
break;
case 12:
group = [lArray objectAtIndex:row];
cell.textLabel.text = group;
break;
}
}
return cell;}
和我的一些其他方法:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"cell is touched");
if(checkbox.state == UIControlStateNormal){
[checkbox setImage:[UIImage imageNamed:@"[email protected]"] forState:UIControlStateHighlighted];
}else if (checkbox.state == UIControlStateSelected) {
[checkbox setImage:[UIImage imageNamed:@"[email protected]"] forState:UIControlStateHighlighted];
}}
-(void)checkboxClicked:(UIButton *)sender{
sender.selected = !sender.selected;
UITableViewCell *ownerCell = (UITableViewCell *)sender.superview;
NSIndexPath *ownerCellIndexPath = [self.myTableView indexPathForCell:ownerCell];
if(sender.selected){
}else{
}}
沒有幫助,謝謝你回覆! – 2012-04-19 20:28:42