2012-06-20 3 views
1

이 질문에 대한 대답은 간단하지만 충분히 찾을 수없는 것 같습니다.UITableViewCell은 Nothing입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell==nil) 
    { 
     NSLog(@"Cell is nil!"); 
    } 

    return cell; 
} 

을하지만 내 로그 출력에 나는

전지는 무기 호입니다 얻을 : 내 UITableViewController에 다음 코드를!

즉시 나중에 인해 캐치되지 않는 예외 'NSInternalInconsistencyException'응용 프로그램 종료

, 이유 : ': cellForRowAtIndexPath : jQuery과 데이터 소스는있는 tableView에서 셀을 반환해야한다' * 먼저 던져 호출 스택 : (0x1b68d72 0x135fe51 0x1b68bd8 0xb0e315 0xcb373 0x63578 0xcb1d3 0xcff19 0xcffcf 0xb9384 0xc952e 0x691bc 0x13736be 0x215c3b6 0x2150748 0x215055c 0x20ce7c4 0x20cf92f 0x2171da2 0x1b4b4 0x1be63 0x2c2be 0x2cf9f 0x1f3fd 0x1ac5f39 0x1ac5c10 0x1adeda5 0x1adeb12 0x1b0fb46 0x1b0eed4 0x1b0edab 0x1b28f을 0x1 ce71 0x253d 0x2465) 의 libC++ abi.dylib : 예외 (lldb)을 던지는라고 종료

사람이 이런 일이, 그리고 더 중요한 것은, 어떻게 그것을 해결하기 위해 왜 어떤 생각을 가지고 있습니까? 사전에

감사합니다.

답변

3

당신은 셀을 작성해야합니다 경우 전무 때문에 테이블 뷰 캐시에서 방법

[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

반환되지 않는 세포.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:NSIndexPath*)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    //configure cell 

    return cell; 
} 
+0

감사합니다. 그것은 작동합니다! – gtmtg

0

dequeueReusableCellWithIdentifier 하나가 재사용 할 수있는 경우에 통과 식별자와 이미 생성 된 셀을 반환합니다.

그렇지 않은 경우 사용자가 생성해야합니다.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCellID]; 
if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 
            reuseIdentifier:kCustomCellID] autorelease]; 
} 
0

예, 방법 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];, 그것은 화면에 대한 몇 가지 세포를 할당합니다, 당신이있는 tableView를 들어,이 식별자 어떤 세포를 할당하지 않은 CellIdentifier.but에 할당 된 셀을 재사용을 의미 그리고 그것은 당신이 이렇게 할 경우, 당신은

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell==nil) 
    { 
     NSLog(@"Cell is nil!"); 
     cell = [[[UITableViewCell alloc] initWithSyle:UITableViewCellStyleNormal reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    return cell; 
} 

이 시험을 작동 것을 발견 할 것이다, 식별자로 세포를 다시 사용합니다.

0

이 클래스에 interface builder을 사용합니까? 그렇다면 테이블보기에서 참조를 만드는 것을 잊지 마십시오. 나는 똑같은 문제가 없었고 이것이 나에게도 마찬가지였다.

관련 문제