简体   繁体   中英

Two table view in one view controller - pushing any view controller is not working

I have two table view in one view controller.

They works great! But they are not pushing to any vc.

Under -(void) viewDidLoad method in my main view controller:

horizontalViewController = [[HorizontalViewController alloc] init];

verticalViewController = [[VerticalViewController alloc] init];


[horizontalTableView setDataSource:horizontalViewController];

[verticalTableView setDataSource:verticalViewController];


[horizontalTableView setDelegate:horizontalViewController];

[verticalTableView setDelegate:verticalViewController];


horizontalViewController.view = horizontalViewController.tableView;

verticalViewController.view = verticalViewController.tableView;

What can I do?

Thanks.

refer a following code. If you want use a pushViewController method. You must be have a NavigationViewController. so, your structure is a little complex. one ViewController has number of Two TableViewController. one ViewController is not have NavigationController. NavigaitonViewController necessarily belong to the app when it runs because it should be configured.

TwoTableViewsAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    UINavigationController *naviController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
    [window setRootViewController:naviController];
    [window makeKeyAndVisible];

    return YES;
}

TwoTableViewsViewController.m

- (void)viewDidLoad {

    if (firstController == nil) {
        firstController = [[FirstTVContoller alloc] init];
    }
    if (secondController == nil) {
        secondController = [[SecondTVController alloc] init];
    }

    [firstTable setDataSource:firstController];
    [secondTable setDataSource:secondController];

    [firstTable setDelegate:firstController];
    [secondTable setDelegate:secondController];

    firstController.view = firstController.tableView;
    secondController.view = secondController.tableView;

    firstController.rootViewController = self;
    secondController.rootViewController = self;

    [super viewDidLoad];
}

FirstTVContoller.h , SecondTVController.h

#import <Foundation/Foundation.h>

@interface FirstTVContoller : UITableViewController <UITableViewDataSource, UITableViewDelegate>{
    NSMutableArray *items;
}

@property (nonatomic, retain) UIViewController *rootViewController;

@end

FirstTVContoller.m , SecondTVController.m

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    VerticalDetailViewController *verticalDetailViewController = [[VerticalDetailViewController alloc] initWithNibName:@"VerticalDetailViewController" bundle:nil];
    [[self.rootViewController navigationController] pushViewController:verticalDetailViewController animated:YES];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM