2013-07-08 9 views
12

Nella storyboard ho aggiunto una vista tavolo al mio controller della vista, ho Ctrl trascinato il TableView per la viewController e collegato "delegare" e "origine dati". Nel file (.h) ho aggiunto <UITableViewDataSource,UITableViewDelegate> ma quando eseguo l'app viene visualizzato solo un errore SIGABRT (?) E l'app si arresta in modo anomalo. Cosa dovrei fare?Come utilizzare TableView all'interno di viewcontroller?

+0

° errore: #import #import "AppDelegate.h" int main (int argc, char * argv []) { @ autoreleasepool { return UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate class])); }} – b3rge

+0

Avete implementato i metodi richiesti di UITableViewDataSource? – ColdLogic

+0

No, non ho @ColdLogic – b3rge

risposta

19

Fin qui tutto bene, devi solo implementare UITableViewDataSource e UITableViewDelegate nel file di implementazione.

funzioni richieste sono le seguenti;

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

Grazie, mi ha aiutato molto! – b3rge

Problemi correlati