2013-05-07 2 views
3

Я пытаюсь создать таблицу с использованием пользовательского UITableViewCell, но после удаления ячейки и при попытке загрузить представление, я получаю ошибку EXC_BAD_ACCESS, здесь я получаю данные из словарь и загрузить его в режим таблицы.Получение плохого доступа при удалении ячейки и перезагрузке табличного представления

Код для моей таблицы выглядит следующим образом:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    cell = (uploadCustomCell *)[tabelView1 dequeueReusableCellWithIdentifier:@"cell"]; 
    [cell setSelectionStyle:UITableViewCellEditingStyleNone]; 
    if (cell == nil) { 
     [[NSBundle mainBundle]loadNibNamed:@"uploadCustomCell" owner:self options:nil]; 
     cell = (uploadCustomCell *)self.uploadCustomcell; 
    } 
    saveBtnCcell.hidden = YES; 
    cell.textNamefield.hidden = YES; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    [cell.defaultSwitch setEnabled:NO]; 
    NSMutableArray *dictionary = [contents objectAtIndex:indexPath.row]; 
    NSLog(@"dict dict :%@",dictionary); 
// 
    cell.nameLabelCell.text = [dictionary valueForKey:@"VideoName"]; 
    cell.userName.text = [dictionary valueForKey:@"User"]; 
    NSString *defaultVideo = [dictionary valueForKey:@"DefaultVideo"]; 

    if ([defaultVideo isEqualToString:@"1"]) { 
     [cell.defaultSwitch setOn:YES animated:YES]; 
    } 
    else { 
     [cell.defaultSwitch setOn:NO animated:YES]; 
    } 

    [cell.defaultSwitch addTarget:self action:@selector(setState:) forControlEvents:UIControlEventValueChanged]; 
    cell.thumbImg.image = [arrayimage objectAtIndex:indexPath.row]; 
    VideoNameTextField.hidden = YES; 
    return cell; 
} 

- (void)setState:(id)sender { 
    state = [sender isOn]; 
    // NSString *rez = state == YES ? @"YES" : @"NO"; 
    NSLog(@"state.........:%d",state); 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath  *)indexPath { 
    NSLog(@"height:%f",uploadCustomcell.frame.size.height); 
    return 207; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSMutableArray *dictionary = [contents objectAtIndex:indexPath.row]; 
    NSLog(@"Dictionary:%@",dictionary); 
    NSLog(@"indexpath:%@",indexPath); 
    // 
    NSLog(@"at index%d obj:%@",indexPath.row,dictionary); 
    NSString *nameDetails = [dictionary valueForKey:@"VideoName"]; 

    guid = [dictionary valueForKey:@"GUID"]; 

    detailsNameLbl.text = nameDetails; 
    detailsVehImg.image = [arrayimage objectAtIndex:indexPath.row];; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle: 
     (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [contents removeObjectAtIndex:indexPath.row]; 
     [tabelView1 reloadData]; 
    } 
} 
+0

numberOfRows может быть проблема ???? –

+0

, в какой строке вы получаете эту ошибку? – Balu

+1

Что вы сделали в этом методе numberOfRowsInSection –

ответ

0

Попробуйте это: [Tableview deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation: UITableViewRowAnimationFade];

Вы должны использовать этот метод также:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return UITableViewCellEditingStyleDelete; 
} 



- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
if (editingStyle == UITableViewCellEditingStyleDelete) { 
[contents removeObjectAtIndex:indexPath.row]; 
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
//[tabelView1 reloadData]; 

}

Смежные вопросы