gpt4 book ai didi

ios - 在选择一些单元格后向上和向下拖动时,我的复选标记消失了

转载 作者:行者123 更新时间:2023-11-28 19:08:40 25 4
gpt4 key购买 nike

#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

最佳答案

您收到此错误是因为您试图将对象插入到此行指向的 NSArray。

-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x80343a0

addObject 不是 NSArray 而不是 NSMutableArray 的方法

Please make your array NSMutableArray to add or delete some item at run time because NSArray always initialized with items at compile time not run time.

希望这对您有所帮助。

关于ios - 在选择一些单元格后向上和向下拖动时,我的复选标记消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17873777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com