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?
12
A
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;
}
+0
Grazie, mi ha aiutato molto! – b3rge
° errore: #import #import "AppDelegate.h" int main (int argc, char * argv []) { @ autoreleasepool { return UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate class])); }} –
b3rge
Avete implementato i metodi richiesti di UITableViewDataSource? – ColdLogic
No, non ho @ColdLogic – b3rge