2009-07-06 6 views
-1

섹션을 만들면 오류가 발생합니다.UITableview 섹션 오류 - objc_msgSend

이미 섹션 색인을 0과 1로 설정하려고 시도했지만 도움이되지 않았습니다.

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

    static NSString *CellIdentifier = @"Cell"; 
    static NSString *CellIdentifier1 = @"Cell1"; 


    if(indexPath.section == 1) { 
     if(indexPath.row == 0) { 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.text = @"test 1"; 

     } 

     return cell; 
    } 
    else if(indexPath.row == 1) { 
     UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell1 == nil) { 
      cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
      cell1.text = @"test 2"; 

     } 

     return cell1; 
    } 
    } 

else if(indexPath.section == 2) { 
    if(indexPath.row == 0) { 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
      cell.text = @"test 1"; 

     } 

     return cell; 
    } 
    else if(indexPath.row == 1) { 
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell1 == nil) { 
      cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
      cell1.text = @"test 2"; 

     } 

     return cell1; 
    } 
} 
} 

답변

0

섹션과 행이 최대한 멀리 볼 수있는 0에서 시작, 당신은, 섹션 0 indexPath에 대한 셀을 반환하지 않는 0

편집을 행 : 재 게시 소스 코드를 (더 읽기 쉬운) :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    static NSString *CellIdentifier1 = @"Cell1"; 
    if(indexPath.section == 1) { 
     if(indexPath.row == 0) { 
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
      if (cell == nil) { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
       cell.text = @"test 1"; 
      } 
      return cell; 
     } 
     else if(indexPath.row == 1) { 
      UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
      if (cell1 == nil) { 
       cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
       cell1.text = @"test 2"; 
      } 
      return cell1; 
     } 
    } 
    else if(indexPath.section == 2) { 
     if(indexPath.row == 0) { 
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
      if (cell == nil) { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
       cell.text = @"test 1"; 
      } 
      return cell; 
     } 
     else if(indexPath.row == 1) { 
      UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
      if (cell1 == nil) { 
       cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
       cell1.text = @"test 2"; 
      } 
      return cell1; 
     } 
    } 
} 
+0

섹션은 실제로 1에서 시작됩니다. '- (NSInteger) numberOfSectionsInTableView : (UITableView *) tableView' 함수는 항상 적어도 '1'이 아닌 '0'을 반환해야합니다. 또한 충돌을 일으킬 수 있습니다. – Jake

+1

실제로 항상 1 섹션이지만 indexpath의 첫 번째 섹션 번호는 0입니다. indexPath.section == 0 -> 첫 번째 섹션 – drvdijk

+0

+1 또한 컴파일러는 (비어 있음) 함수를 통해 경로 중 하나가 아무 것도 반환하지 않는다는 사실에 대해 경고해야합니다. – frankodwyer

0

기본 질문. U - (NSInteger) tableView : (UITableView *) tableView numberOfRowsInSection : (NSInteger) 섹션의 섹션 수를 업데이트했습니다. 정상 obj msg 보내기 오류 .. 사용자가 출시 한 무언가 또는 자신이 소유하지 않은 무언가를 처리 중일 때 ... 예를 들어 이 코드를 작성한 테이블보기의 init 메소드 sectionArray = [NSArray arraywithcontentsoffile : xyz.plist]

그리고 RowsInSection의 수에서 다음과 같은 것을 사용하십시오 : [섹션 배열 개수];

여기서 sectionArray는 인스턴스 변수입니다 ..

-1

답장을 보내 주셔서 감사합니다!

전체 코드를 한 번 더 작성하고 코드 줄을 추가 할 때마다 실행했습니다. 도움이되었습니다. 문제는 if(indexPath.section == 0) 인 것 같습니다. 3 섹션 중 2 섹션에 대해서만 콘텐츠를 설정합니다.

하지만 wheather가이 문제인지 잘 모르겠습니다.

큰 도움을 주셔서 감사합니다.

초보자 용 목표로는 쉽지 않습니다. :)

관련 문제