2013-02-10 3 views
1

방금 ​​튜토리얼에서 간단한 단계를 따라 50 행을 가진 간단한 TableView를 만들었지 만 "Signal SIGABRT"를 얻습니다./ 내가 만든 TableViewController-Class가있는 Storyboard에 TableView를 연결했습니다. 스택 오버플로신호 SIGABRT 간단한 테이블보기

#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)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 50; 
} 

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

    // Configure the cell... 

    cell.textLabel.text = [NSString stringWithFormat:@"Row %i",indexPath.row]; 

    return cell; 
} 

답변

2

에 오신 것을 환영합니다 :

여기 내 간단한 코드입니다! UITableViewCell을 설정하기위한 표준 방법이 약간 조금 변경되었습니다. 이 tableViews는 -tableView: dequeueReusableCellWithIdentifier: forIndexPath: 방법을 사용하여 당신이 그것에게 새로운 방법 (-tableView: dequeueReusableCellWithIdentifier: forIndexPath)을 수행 할 경우 이전의 튜토리얼과 책 (대부분이) 당신도 [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];를 추가 할 필요가 tableView: dequeueReusableCellWithIdentifier:

를 사용하는 동안 템플릿 코드의 엑스 코드를 제공한다는 것을 의미 viewDidLoad에서 (또는 스토리 보드/nib에서 프로토 타입 셀 재사용 ID를 설정하고 셀 유형을 적절하게 설정합니다. 기본 셀은 기본 셀에 대해 수행해야합니다.)

오래된 방법 (tableView: dequeueReusableCellWithIdentifier:)는 일반적으로 같은 if 문 뭔가 뒤에 :

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

이 간단 물건 공정성 대부분의 튜토리얼, 정말 동안

합니다 (\\Configure the cell. . . 코멘트입니다) 할 당신이 두 개의 -tableView:dequeueReusableCell 방법 사이의 작은 차이를 알지 못한다면 초보자에게 혼란 스러울 수 있다고 생각하는 오래된 방법을 가르쳐주십시오. 새로운 방법을 보여주는 자습서는 here

입니다.