2013-07-08 13 views
12

W scenorysie dodałem widok tabeli do kontrolera widoku, Ctrl przeciągnąłem widok TableView do Viewcontroller i połączono "delegate" i "datasource". W pliku (h) dodałem <UITableViewDataSource,UITableViewDelegate>, ale po uruchomieniu aplikacji pojawia się błąd SIGABRT (?) I aplikacja ulega awarii. Co powinienem zrobić?Jak korzystać z TableView wewnątrz viewcontroller?

+0

błąd th: #import #import "AppDelegate.h" Int główne (Int ARGC char * argv []) { @ autoreleasepool { return UIApplicationMain (argc, argv, zero, NSStringFromClass ([klasa AppDelegate])); } } – b3rge

+0

Czy zaimplementowałeś wymagane metody UITableViewDataSource? – ColdLogic

+0

Nie, nie mam @ColdLogic – b3rge

Odpowiedz

19

Do tej pory wystarczy wprowadzić implementację UITableViewDataSource i UITableViewDelegate w pliku implementacji.

Wymagane funkcje są następujące;

- (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

Dzięki, bardzo mi to pomogło! – b3rge

Powiązane problemy