2012-07-25 3 views
0

다음은 nib 파일의 tableviewcell을 tableview에 넣는 코드로 사용됩니다. 나는 tableviewcell을 tableview와 같은 펜촉으로 찍었다. 나는 또한 viewdidload에있는 세포를 초기화하려했지만 아무 것도하지 않았다. 내가 할IB의 UITableViewCell이 값을 NULL로 표시합니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"identifier"; 
    NSLog(@"the cellidentifier is %@", CellIdentifier); 
    bookmarksTableViewCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    NSLog(@"the cell is %@", bookmarksTableViewCell); 
    return bookmarksTableViewCell; 
} 

오류가 나는 IB의 연결을 확인하고 그들도 재배 선 한

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 

하지만 결과는 동일납니다. 셀을 NSLog하려고하면 null이됩니다.

+0

Interface Builder에서 셀의 식별자를 "indentifier"로 설정 했습니까? 나는 그것을 "Custom Cell"이나 "Bookmark Cell"또는 무엇인지 식별하는 것과 같은 다른 것이라고 부를 것입니다. 여기서 식별자 "식별자"가있는 셀을 호출합니다. –

답변

1

당신은 당신 만 생각하면 내가 그것을 포함하는 것이 필요하면 그렇게

static NSString *CellIdenetifier = @"Cell"; 

BookMarksTableViewCell *cell = (BookMarksTableViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if(cell == nil){ 
    cell = [[BookMarksTableViewCell alloc] initWithStyle:UITableViewCellStyleSubTitle reuseIdentifer:CellIdentifier]; 
} 

임 확실하지 않은 것처럼 할 필요가있다.

+0

자막은 하나의 대문자입니다. –

+0

답장을 보내 주셔서 감사합니다. 충돌 문제를 해결하지만 XIB 파일에서이 UITableViewCell에 넣은 그래픽 요소 (예 : 정적 UILabel)가 표시되지 않습니다. 대신 빈 셀을 얻습니다. 어떤 제안? – NSFeaster

+0

당신은'cell.labelName.text = @ "text"'와 비슷한 것을 했는가? 라벨의 텍스트를 설정하는 방법. 그것을 펜촉에 올바르게 연결했는지 확인하십시오. 또한 h에서'@ property'를, 라벨에서 m에'synthesize'를 사용하십시오. – BigT

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


    static NSString *CellIdentifier = @"identifier"; 
    NSLog(@"the cellidentifier is %@", CellIdentifier); 

    bookmarksTableViewCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (bookmarksTableViewCell == nil){ 
      //allocate your cell here 
    } 

    return bookmarksTableViewCell; 
+0

답장을 보내 주셔서 감사합니다. 충돌 문제를 해결하지만 XIB 파일에서이 UITableViewCell에 넣은 그래픽 요소 (예 : 정적 UILabel)가 표시되지 않습니다. 대신 빈 셀을 얻습니다. 어떤 제안? – NSFeaster

+0

은 IB의 해당 uilabel에 고유 한 태그 (9876 또는 무작위이지만 고유 한 태그)를 설정합니다. 귀하의 cellForRow에서 UILabel * theLabel = (UILabel *) [bookmarksTableViewCell viewWithTag : 9876]. 그리고 나서 당신이하고 싶은 것은 무엇이든간에 LabLabel –

+0

지금 완전히 다른 접근법으로 코드를 작성했습니다. 이제는 잘 작동하는 것 같습니다. 도와 줘서 고마워. – NSFeaster

1

물론 null입니다.

테이블보기는 큐에서 사용할 수보다 더 많은 세포를 표시 할 필요가있는 경우

, 그것은 세포의 충분한 양이 할당 될 때까지 새로운 세포 생성을위한 데이터 소스를 물어

dequeueReusableCellWithIdentifier: 

에서 전무를 반환합니다. NULL 확인 :

bookmarksTableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if (bookmarksTableViewCell == NULL) 
    bookmarksTableViewCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStylePlain reuseIdentifier:cellIdentifier] autorelease]; 

return cell; 

아, ps. : Interface Builder에 대해 잊어 버려.

+0

답장을 보내 주셔서 감사합니다. 오류는 이제 사라졌지만 tableview에 표시되는 셀에는 label, 배경색 또는 tableviewcell에 넣은 다른 그래픽 속성이 없습니다. – NSFeaster

+0

수동으로 설정해야합니다.이를 관리하는 것은 IB의 범위를 훨씬 뛰어 넘습니다. 프로그래밍을 원할 경우 언젠가는 직접 코드를 입력해야합니다. 나는이 시간이 당신을 위해왔다 것을 짐작한다. –

+0

^답장을 보내 주셔서 감사합니다. 나는 일반적으로 모든 cellForRowAtIndexPath 코딩을 손으로 처리하지만 이번에는이 tableviewcell에서 그래픽 요소를 많이 사용하고 관리하는 것이 매우 복잡 할 수 있다는 점을 감안할 때 IB의 UITableViewCell 객체를 사용하는 것이 편리 할 수 ​​있다고 생각했습니다. IB가 UiTableViewCell 객체를 제 위치에 가지고 있다는 것을 고려하면 왜 그것이 IB의 범위 밖에 있다고 생각합니까? 고맙습니다. – NSFeaster

관련 문제