gpt4 book ai didi

ios UITableViewcell 设置复选标记但滚动时间复选标记是自动隐藏并尝试解决它崩溃

转载 作者:行者123 更新时间:2023-11-29 03:02:34 25 4
gpt4 key购买 nike

我有一个表格 View 单元格,这是从一个数组绑定(bind)并选择多个单元格并设置为复选标记,但是当我滚动表格时,复选标记会自动隐藏然后我在 stackoverflow 上搜索,找到一个答案链接是 UITableview accessory type disappear while scrolling

我尝试了这段代码,但应用程序崩溃了这是我的代码,请帮助我

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *simpleTableIdentifier = @"FirstTableViewCell";

FirstTableViewCell *cell = (FirstTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FirstTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if(tableView ==nurseTypeTable){
cell.lbl1.text = [arrayNurseType objectAtIndex:indexPath.row];

if(_nurseArray.count != nil){
// if (_nurseArray == nil || [_nurseArray count] == 0) {
NSNumber *rowNsNum = [_nurseArray objectAtIndex:indexPath.row];
if ( [arrayNurseType containsObject:rowNsNum] )
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}

return cell;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString * cellValue=nil;
if (tableView==nurseTypeTable) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

//Here is for Check
if(cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
//here i add in array
cellValue=[arrayNurseType objectAtIndex:indexPath.row];
NSLog(@"%@",cellValue);

[_nurseArray addObject:cellValue];
NSLog(@"%@",_nurseArray);

}
//Here is for uncheck
else {
cellValue=[arrayNurseType objectAtIndex:indexPath.row];
[_nurseArray removeObject:cellValue];
cell.accessoryType = UITableViewCellAccessoryNone;
NSLog(@"Remove Array %@",_nurseArray);
}
// [tableView deselectRowAtIndexPath:indexPath animated:YES];


}

在函数cellForRowAtIndexPath **

NSNumber *rowNsNum = [_nurseArray objectAtIndex:indexPath.row];** is creash on debug time 
arrayNurseType = [NSMutableArray arrayWithObjects:@" Nurse ",@"One",nil]

最佳答案

你应该使用

     if(tableView ==nurseTypeTable){
cell.lbl1.text = [arrayNurseType objectAtIndex:indexPath.row];

if(_nurseArray.count != nil){
// if (_nurseArray == nil || [_nurseArray count] == 0) {
if ( [_nurseArray containsObject:indexPath] )
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}

return cell;
}
}

关于ios UITableViewcell 设置复选标记但滚动时间复选标记是自动隐藏并尝试解决它崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23149225/

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