#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.list count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *checkMarkCellIdentifier = @"CheckMarkCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:checkMarkCellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:checkMarkCellIdentifier];
}
NSUInteger row = [indexPath row];
NSUInteger oldRow = [self.lastIndexPath row];
cell.textLabel.text = [self.list objectAtIndex:row];
cell.accessoryType = (row == oldRow && self.lastIndexPath != nil) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;
}
#pragma Mark -
#pragma Mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.tickList = [[NSMutableArray alloc]init];
int newRow = [indexPath row];
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if(newCell.accessoryType == UITableViewCellAccessoryCheckmark)
{
self.lastIndexPath = indexPath;
}
int oldRow = (self.lastIndexPath != nil) ? [self.lastIndexPath row] : -1;
if(newRow == oldRow)
{
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:self.lastIndexPath];
if(oldCell.accessoryType == UITableViewCellAccessoryCheckmark)
{
oldCell.accessoryType = UITableViewCellAccessoryNone;
self.lastIndexPath = nil;
[self.tickList removeObject:indexPath];
}
else{
oldCell.accessoryType = UITableViewCellAccessoryCheckmark;
self.lastIndexPath = indexPath;
[self.tickList addObject:self.lastIndexPath];
}
}
else if (newRow != oldRow) {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:self.lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryCheckmark;
self.lastIndexPath = indexPath;
[self.tickList addObject:self.lastIndexPath];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
上記のコードから、この行 [self.tickList addObject:self.lastIndexPath] を使用して、選択したセルを tickList という名前の可変配列に格納するために毎回使用し、削除するために removeObject を使用しましたが、うまくいきません。私はそのためにエラーが発生しています
2013-07-26 11:06:30.339 NAV[762:c07] Application windows are expected to have a root view controller at the end of application launch
2013-07-26 11:06:32.117 NAV[762:c07] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x80343a0
2013-07-26 11:06:32.118 NAV[762:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x80343a0'
*** First throw call stack:
(0x1c9d012 0x10dae7e 0x1d284bd 0x1c8cbbc 0x1c8c94e 0x5a3c 0xce285 0xce4ed 0xad85b3 0x1c5c376 0x1c5be06 0x1c43a82 0x1c42f44 0x1c42e1b 0x1bf77e3 0x1bf7668 0x1effc 0x264d 0x2575)
libc++abi.dylib: terminate called throwing an exception