2013-06-17 3 views
0

다음은 tutorial이며 다음과 같습니다. 이 기사에서 셀은 프로그래밍 방식으로 등록됩니다. 나는 SHCAppDelegateiOS : 셀이 TableView에 등록되어 있지 않습니다.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    self.viewController = [[SHCViewController alloc] initWithNibName:@"SHCViewController" bundle:nil]; 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

SHCViewController.m

을위한 모든 단계를 따라 코드를 다운로드하고 그것을 내 비교하지만 문제
SHCAppDelegate.m

@implementation을 알아낼 수 없습니다

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 

     _toDoItems = [[NSMutableArray alloc] init]; 
     [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Feed the cat"]]; 
     [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Buy eggs"]]; 
     [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Pack bags for WWDC"]]; 

     } 
} 
- (void)viewDidLoad:(BOOL)animated 
{ 
    [super viewDidLoad]; 
    self.tableView.dataSource = self; 
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; 
} 

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return _toDoItems.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *ident = @"cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath]; 
    int index = [indexPath row]; 
    SHCToDoItem *item = _toDoItems[index]; 
    NSLog(@"%@",item.text); 
    cell.textLabel.text = item.text; 

    return cell; 
} 

여기 NSLog 내부 tableView:(UITableView *)tableView cellForRowAtIndexPath:은 콘솔에 인쇄되지 않습니다. 데이터 소스를 설정 한 후

답변

0

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.tableView.dataSource = self; 
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; 
    [self.tableview reloadData]; 
} 
+0

감사를 시도 [self.tableview reloadData];

로 다시로드 테이블 메서드를 호출합니다. 나는 문제가있다. 그것은 viewDidLoad : (BOOL) 애니메이션입니다. 방금 - (id) viewDidLoad를 사용했을 때 제대로 작동했습니다. 하지만 왜 그런지 몰라? – Navjot

+0

@Navjot이 메소드를 호출하는 올바른 방법입니다.이 메소드는 기본 viewcontroller 대리자 메커니즘 인 -http : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html에 있습니다. # // apple_ref/occ/instm/UIViewController/viewDidLoad –

관련 문제