刷新UISplitView控制器的主TableView [英] Refreshing Master TableView of a UISplitView Controller
问题描述
在将我们最新的iPhone App移植到通用应用程序时,我决定在TabBarController内使用iPad的SplitView Controller.由AppDelegate管理每个Tab的SplitViewController.
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.
一切正常,但是我的问题是我的MasterView(在SplitView的左侧)包括4个Category-Buttons来更改TableViews数据.如果单击按钮之一,则TableView需要刷新/重新加载数据,以显示所选类别的新内容. 我创建了一个函数来进行更改,并在界面生成器中将我的按钮链接到了它.
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];
,但是SplitView不显示刷新.仍然是旧数据. 我用NSLog进行了一些测试,以检查我的功能是否正常工作.没问题.
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.
然后,我尝试通过SplitViewController本身访问tableView,如下所示:
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.
我错过了什么吗?有什么方法可以轻松地在SplitView中重新加载TableViewController吗?我已经读过一些有关通过NotificationCenter向代表发送通知的信息,但是仍然找不到有用的资源.
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.
为了理解我的结构,这是我在AppDelegates"didFinishLaunchingWithOptions"方法中设置SplitView的方法:
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++;
推荐答案
尝试:
PresetController *detail = [split.viewControllers lastObject];
索引为0的视图控制器将是您的主"控制器,而我认为详细信息"控制器是具有您要更新的表视图的控制器.
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.
您不想在选项卡视图中使用UISplitViewController
;它必须是rootViewController
.
You don't want to use a UISplitViewController
inside a tab view; it needs to be the rootViewController
.
这篇关于刷新UISplitView控制器的主TableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!