2012-10-23 1 views
0

안녕하세요. 감사합니다. 나는 사용자가 단면 뷰로 변경할 수있는 테이블 뷰를 가지고있다. 표준보기에서는 모두 잘되지만 사용자가 단면 뷰로 전환하면 (-commitEditingStyle :) 함수를 사용하여 행을 삭제하려고 할 때 충돌이 발생합니다. 이 기능에서 나는 무엇을 놓치고 있습니까? 섹션이 만들어지면 행을 어떻게 삭제해야합니까? (I 배열의 사전이다 wchich PLIST에서 내 테이블을로드 각 인덱스가있는 TableView의 행 되..)섹션을 사용할 때 uiTableView를 어떻게 편집 (즉, 행 삭제)합니까?

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if ([strTitle isEqualToString:@"sectionView"]) { 

     @try { 


     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      // Delete the row from the data source. 
      // NSMutableDictionary *book =[[NSMutableDictionary alloc]init]; 
      NSMutableDictionary *mynewList = [[NSMutableDictionary alloc]init]; 
      mynewList = [[self.TitleDis valueForKey:[[[self.TitleDis allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 
      NSMutableArray *sectionRow = [mynewList objectForKey:@"Dis"]; 


      [sectionRow removeObjectAtIndex:indexPath.row]; 

      [mynewList writeToFile:[self dataFilePath] atomically:YES]; 

      // 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

     } else if (editingStyle == UITableViewCellEditingStyleInsert) { 
      // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
     } 
     } 
     @catch (NSException *exception) { 
      NSLog(@"hello error...%@",exception); 
     } 



    } 

    else { 
    /////////////////////// STANDARD VIEW 

    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source. 
     [distribArray removeObjectAtIndex:indexPath.row]; 
     // 
     //  NSMutableArray *contents = [[NSMutableArray alloc] init]; 
     //  [contents addObject:myMasterList]; 
     //  //[contents addObject:[NSArray arrayWithObjects:arraydata.text,distroName.text,destorEmail.text, nil]]; 

     [distribArray writeToFile:[self dataFilePath] atomically:YES]; 

     // 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

    } else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
    } 
     ////////////////////////////////// 
    } 
} 

콘솔 - [__ NSCFString removeObjectAtIndex :] : 미정 선택기 인스턴스 0xe4bd3f0 전송

당신이 볼 수 있듯이 나는 형식을 가지고 놀고있다 .... 다음에 무엇을 시도 해야할지 모르겠다 ??? 감사.

내가 단면 무엇을 의미 : 당신이 다음 mynewList을 allocing하고 어디

NSMutableDictionary *mynewList = [[NSMutableDictionary alloc]init]; 
mynewList = [[self.TitleDis valueForKey:[[[self.TitleDis allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 

즉시 덮어 쓰기 : enter image description here

+0

'단면보기'란 무엇을 의미합니까? 테이블 뷰의 그룹 스타일을 의미합니까? – Tobi

답변

0

두 가지 문제가 있습니다. 아래의 라인은 누출을 일으킬 것이므로 이런 방식으로 사용하면 안됩니다.

대신이 당신이 그것을 넣을 수의
NSMutableDictionary *mynewList = [[NSMutableDictionary alloc]init]; 
      mynewList = [[self.TitleDis valueForKey:[[[self.TitleDis allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 

,

NSMutableDictionary *mynewList = [[self.TitleDis valueForKey:[[[self.TitleDis allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 

또 다른 한가지는,

[mynewList objectForKey:@"Dis"];는 항상 배열이 아닌 그것은 때로는 문자열로오고있다. 데이터 구조를 점검하고 배열인지 확인하십시오.

이 같은

id obj = [mynewList objectForKey:@"Dis"]; 
NSLog(@"%@", [[obj class] description]); 

을 시도하고 NSLog 인쇄 obj의 데이터 유형이 무엇인지 확인합니다. NSMutableArray이고 NSString이 아니라는 것을 확인하십시오.

+0

'mynewList'는 OP와 같이 삽입되거나 재 할당되어서는 안됩니다. 그러나 ARC로 컴파일하면 메모리 누수가 발생하지 않습니다. (코드에 단일 보유 또는 릴리스가 없으므로 ARC로 가정합니다.) –

+0

ARC가 사용되는 경우 사실입니다. 그러나 여전히 첫 번째 라인은 그렇게하는 것이 의미가 없습니다. 그는 직접 지정할 수 있습니다. 그러나 ARC가이 코드에서 사용되는지 확실하지 않습니다. 그것은 매우 일반적인 주석이었습니다. – iDev

0

은 그래서 하나, 당신이있어.

하지만 디버거에서 sectionRow의 유형을 확인해야한다고 생각합니다. 내 생각 엔 NSString입니다.

데이터 구조에 대해 더 알지 못하면서 어떤 일이 벌어지고 있는지 알기가 어렵습니다.

관련 문제