我在创建UITableView中的CheckMarkAccessoryView时遇到了问题。当我在表中选择一行时,我可以得到该行的选中标记,但随机表中的其他一些行也会得到复选标记。我只需要那个单元格就可以得到复选标记。我可以怎么做?我正在编写一个独占列表。以下是我用过的代码。iPhone的UITableViewCellAccessoryCheckMark
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(tableView==tableView1) { return […arraycount1…. ]; } else { return […arraycount2…. ]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } else { UIView* subview; while ((subview = [[[cell contentView] subviews] lastObject]) != nil) [subview removeFromSuperview]; } if(tableView == tableView1) { cell.textLabel.text=[array1 objectAtIndex:indexPath.row]; } else //Tableview2 { cell.textLabel.text=[array2 objectAtIndex:indexPath.row]; } cell.textLabel.font=[UIFont fontWithName:@"Georgia" size:20]; cell.textLabel.textAlignment=UITextAlignmentLeft; [cell setSelectedBackgroundView:border]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastindex]; if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark); { oldCell.accessoryType = UITableViewCellAccessoryNone; } UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath]; if (newCell.accessoryType == UITableViewCellAccessoryNone) { newCell.accessoryType = UITableViewCellAccessoryCheckmark; } }
请问我在哪里错了。 在此先感谢所有的专家。