2012-09-16 5 views
-4

는 I이 대물 C 프로그램 오류 출력을 가지고테이블 뷰 컨트롤러 테스트 프로그램

#import <UIKit/UIKit.h> 

@interface TableViewController : UITableViewController 

@end 

------ 


#import "TableViewController.h" 

@interface TableViewController() 

@end 

@implementation TableViewController 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Uncomment the following line to preserve selection between presentations. 
    // self.clearsSelectionOnViewWillAppear = NO; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
#warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return 50; 
} 

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

    // Configure the cell... 
    cell.textLabel.text = [NSString stringWithFormat:@"Zeile nummer %i",indexPath.row]; 
    return cell; 
} 

/* 
// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 
*/ 

/* 
// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 
     [tableView deleteRowsAtIndexPaths:@[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 
    } 
} 
*/ 

/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the item to be re-orderable. 
    return YES; 
} 
*/ 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Navigation logic may go here. Create and push another view controller. 
    /* 
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 
    // ... 
    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    */ 
} 



@end 

ErrorCode가 : 2012년 9월 16일 21 : 05 : 36.204 renetest2 [1,176 : FB03] * 어설 실패 - [jQuery과 _createPreparedCellForGlobalRow : withIndexPath :] /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061 2012년 9월 16일 21 : 05 : 36.206 renetest2 [1,176 : FB03 * 인해 'NSInternalInconsistencyException'캐치되지 않는 예외 응용 프로그램 종료 , 이유 : 'UITableView dataSource는 tableView에서 셀을 반환해야합니다. cellForRowAtIndexPath :' *** 우선 스택 호출 : (0x14b4022 0xeb4cd6 0x145ca48 0x9ae2cb 0xb1d28 0xb23ce 0x9dcbd 0xac6f1 0x55d21 0x14b5e42 0x1d85679 0x1d8f579 0x1d144f7 0x1d163f6 0x1da3160 0x16767에게 0x25183 0x25c38 0x19634 0x139eef5 0x1488195이 0x13ecff2 0x13eb8da 0x13ead84 0x13eac9b 0x15c65 0x17626 0x1cad 0x1c15 0x1로 0x15e84) 이

+2

문제를 해결하기 위해 수행 한 작업을 설명하고 질문하십시오. 코드와 충돌 로그를 치지 마십시오. –

+1

모든 불필요한 라인을 코드에서 제거하십시오. 다음은 질문을 제기 할 때 권장되는 형식입니다. 1) 오류를 재현하는 방법, 2) 코드가 수행 할 것으로 예상되는 것 (출력/동작), 3) 코드가 실제로하는 것. – BryanH

답변

0

위의 예제에서 대기열에 포함되지 않은 셀이 nil이면 셀이 만들어지지 않습니다. 함수 cellForRowAtIndexPath이 같이해야합니다 :

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

    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier]; 
    } 

    // Configure the cell... 
    cell.textLabel.text = [NSString stringWithFormat:@"Zeile nummer %i",indexPath.row]; 
    return cell; 
} 
0

시도 (lldb) 예외를 throw라고 이해 종료 오류 및 방법 tableView:cellForRowAtIndexPath 봐. // Configure the cell... 대신에 셀을 할당/초기화해야합니다.

0

오류는 여기 :

UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:

이 라인

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

가있게되지 않았 음을 의미합니다 셀 인스턴스를 dequeue하므로 메서드는 nil을 반환합니다.

if (nil == cell) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

그런 다음 새 UITableViewCell 인스턴스를 구성 할 수 있습니다 : 그것은에있는 경우

당신은 cell이 전무 있는지 확인하고 새로운 인스턴스를 작성해야합니다.