刷新 UISplitView 控制器的主 TableView

发布于 2024-12-14 09:07:58 字数 1888 浏览 2 评论 0原文

在将我们最新的 iPhone 应用程序移植到通用应用程序时,我决定在 TabBarController 内使用 iPad 的 SplitView 控制器。 SplitViewController 由 AppDelegate 为每个选项卡进行管理。

一切正常,但我的问题是我的 MasterView(SplitView 左侧)包含 4 个类别按钮来更改 TableViews 数据。如果我单击其中一个按钮,TableView 需要刷新/重新加载数据,以显示所选类别的新内容。 我创建了一个函数来进行更改,并将我的按钮在界面生成器中链接到它。

在我的函数结束时,我尝试像这样刷新控制器:

[self tableView ReloadData];

但 SplitView 不显示刷新。还是旧数据。 我用 NSLog 进行了一些测试,以检查我的函数是否正常工作。没问题。

然后我尝试通过 SplitViewController 本身访问 tableView,如下所示:

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

    [detail.tableView reloadData];

再次,没有错误,..但没有刷新。

我错过了什么吗?有什么方法可以轻松地在 SplitView 中重新加载 TableViewController 吗?我读过一些有关通过通知中心向委托人发送通知的内容,但仍然找不到有用的资源。

编辑:

为了理解我的结构,这是我在 AppDelegates“didFinishLaunchingWithOptions”方法中设置 SplitView 的方法:

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++;

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++;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没︽人懂的悲伤 2024-12-21 09:07:58

尝试:

PresetController *detail = [split.viewControllers lastObject];

索引 0 处的视图控制器将是您的“主”控制器,我认为“详细”控制器是具有您尝试更新的表视图的控制器。

编辑:

您不想在选项卡视图中使用UISplitViewController;它必须是rootViewController

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文