TableView in Tabbar

azrax

Neues Mitglied
Thread Starter
Dabei seit
07.01.2011
Beiträge
18
Reaktionspunkte
0
Hallo Leute,

ich möchte eine Window Based (iPad) App erstellen, deren Grundlage eine Tabbar ist. In den einzelnen Tabs sollen nun TableViews angezeigt werden und bei Drücken auf eine Zeile, soll eine DetailView angezeigt werden.

Mein Problem besteht darin, dass die DetailViews beim drücken nicht angezeigt werden

In meiner AppDelegate erstelle ich die Tabbar:

Code:
....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    tabBarController = [[UITabBarController alloc] init];
    viewControllers = [NSMutableArray array];
    for (int i = 0; i<5; i++) {
		TableViewController *view = [[TableViewController alloc] init];
		[viewControllers addObject:view];
    }
    tabBarController.viewControllers = viewControllers;
    [window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];
    return YES;
}
....

TableViewController:
Code:
....
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    cell.textLabel.text = @"Hallo";
    
    return cell;
}

....

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
	//dvController.selectedCountry = selectedCountry;
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
    detailViewController= nil;
}

....

Ich habe hier noch das Beispielprojekt: Testapp

Ihr könnt es euch ja mal anschauen, vielleicht kann mir jemand Helfen.

Liebe Grüße

Dominik
 
Hi Dominik,

du versuchst die DetailView auf den NavigationController zu pushen. Du hast allerdings keinen NavigationController...

Quick'n'Dirty-Fix: im AppDelegate deinen for-loop wie folgt anpassen:

Code:
for (int i = 0; i<5; i++) {
		UINavigationController *nc = [[UINavigationController alloc] init];
		TableViewController *view = [[TableViewController alloc] init];
		[nc setViewControllers:[NSArray arrayWithObject:view]];
		[viewControllers addObject:nc];
}

VG,
Christian
 
  • Gefällt mir
Reaktionen: below
Zurück
Oben Unten