2013-07-08 38 views
12

Hikaye panosunda, görünüm denetleyicime bir tablo görünümü ekledim, ctrl'yi TableView'u Viewcontroller'a sürükledim ve "temsilci" ve "veri kaynağını" bağladım. (.h) dosyasında <UITableViewDataSource,UITableViewDelegate> ekledim ama uygulamayı çalıştırdığımda sadece bir SIGABRT hatası alıyorum (?) Ve uygulama çöküyor. Ne yapmalıyım?TableView viewcontroller içinde nasıl kullanılır?

+0

inci hatası: alma alma "AppDelegate.h" int ana (int argc, char * argv []) { @ autoreleasepool { döndürür UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate sınıfı])); } } – b3rge

+0

Gerekli olan UITableViewDataSource yöntemlerini uyguladınız mı? – ColdLogic

+0

Hayır, @ColdLogic değil – b3rge

cevap

19

Şimdiye kadar çok iyi, sadece uygulama dosyanızda UITableViewDataSource ve UITableViewDelegate uygulamak zorunda.

Gerekli işlevler aşağıdaki gibidir;

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [regions count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Number of rows is the number of time zones in the region for the specified section. 
    Region *region = [regions objectAtIndex:section]; 
    return [region.timeZoneWrappers count]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    // The header for the section is the region name -- get this from the region at the section index. 
    Region *region = [regions objectAtIndex:section]; 
    return [region name]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *MyIdentifier = @"MyReuseIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]]; 
    } 
    Region *region = [regions objectAtIndex:indexPath.section]; 
    TimeZoneWrapper *timeZoneWrapper = [region.timeZoneWrappers objectAtIndex:indexPath.row]; 
    cell.textLabel.text = timeZoneWrapper.localeName; 
    return cell; 
} 

Here's the link for the Apple documentation

+0

Teşekkürler, bu bana çok yardımcı oldu! – b3rge

İlgili konular