Refreshing Master TableView of a UISplitView Controller

独自空忆成欢 提交于 2019-12-25 04:03:02

问题


while porting our latest iPhone App to an universal app, I decided to use a iPad's SplitView Controller inside of a TabBarController. The SplitViewController is managed by AppDelegate for every Tab.

All works fine, but my problem is that my MasterView (on the left of the SplitView) includes 4 Category-Buttons to change the TableViews Data. If I click one of the buttons, the TableView needs to Refresh/ReloadData, to Display the new Content of the selected category. I created a function to do the changes and linked my buttons to it in the interface builder.

At the end of my function, I tried to refresh the Controller like this:

[self tableView ReloadData];

but the SplitView don't show the refresh. Still the old Data. I tested around a bit with NSLog, to check if my function works correctly. No problems.

Then I tried to access the tableView through SplitViewController itself, like this:

   // PresetController is my TableViewController in the SplitView  
    UISplitViewController *split = (UISplitViewController *)self.parentViewController;    
    PresetController *detail = [split.viewControllers objectAtIndex:0];   

    [detail.tableView reloadData];

Again, no error,.. but no refresh.

Am I missing something? Is there any way to easily reload the TableViewController in SplitView? I've read something about sending a Notfication via NotificationCenter to the delegate, but still couldn't find a helpful ressource.

EDIT:

For understanding my structure, here is the way I set up the SplitView in my AppDelegates "didFinishLaunchingWithOptions" Method:

NSMutableArray *controllers = [NSMutableArray arrayWithCapacity:[self.rootController.viewControllers count]];

        int tabNum = 0;
        for (UIViewController *controller in self.rootController.viewControllers) {



                UISplitViewController *split = [[[UISplitViewController alloc] init] autorelease];
                split.tabBarItem = controller.tabBarItem;
                iPadDetailView *detail = [[iPadDetailView alloc] initWithNibName:@"iPadDetailView" bundle:nil]; // a detail view will come here
                UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:detail] autorelease];

                split.viewControllers = [NSArray arrayWithObjects:controller, nav, nil];


                [controllers addObject:split];
            }
            tabNum++;

回答1:


Try:

PresetController *detail = [split.viewControllers lastObject];

The view controller at index 0 will be your "master" controller, and I presume that the "detail" controller is the one that has the table view you are trying to update.

Edit:

You don't want to use a UISplitViewController inside a tab view; it needs to be the rootViewController.



来源:https://stackoverflow.com/questions/8065849/refreshing-master-tableview-of-a-uisplitview-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!