iOS:从 UITabBar/UINavigationController 应用程序的视图中设置笔尖子视图中的文本 [英] iOS: Setting text in nib subview from view in UITabBar/UINavigationController application

查看:23
本文介绍了iOS:从 UITabBar/UINavigationController 应用程序的视图中设置笔尖子视图中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过另一个视图加载视图时以编程方式设置 UISearchDisplay 的文本值时遇到问题,我的问题是我是否使问题过于复杂并遗漏了某些东西,或者我是否在正确的思考轨道上.

I'm having a problem getting a UISearchDisplay's text value to be set programatically on load of the view by another view and my question is have I overcomplicated my problem and missed something or am I on the right track of thinking.

情况是这样的:我有一个 UITabBarController 作为我的根视图,有 2 个选项卡,都有一个 UINavigationController 设置,所以我可以根据需要推送视图.

Here's the situation: I have a UITabBarController as my root view, there are 2 tabs, both have a UINavigationController setup so I can push views as needed.

Tab 1 有一个 UITableViewController,其中填充了一个类别列表.

Tab 1 has a UITableViewController which is populated with a list of categories.

Tab 2 在它的主视图中有一个 MapView,但我做了一个自定义的 UINavigationItem 视图,将各种按钮和一个 UISearchDisplay 放在 rightBarButtonitem 区域.

Tab 2 has a MapView in it's main view but I have done a custom UINavigationItem view to put various buttons and a UISearchDisplay on the rightBarButtonitem area.

地图视图布局和自定义导航项作为两个单独的视图对象存储在同一个笔尖中.在选项卡 2 的 viewDidLoad() 中,我以编程方式初始化 rightBarButtonItem:

The mapview layout and custom navigation item are stored in the same nib as two separate view objects. In Tab 2's viewDidLoad(), I initialise the rightBarButtonItem programatically with:

UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:buttonBar];
self.navigationItem.rightBarButtonItem = btnItem;
[btnItem release];

一切都启动了,buttonBar 被连接到一个 IBOutlet 作为 searchWhat,我可以从 mapview 的控制器类中与这个对象对话.

Everything fires up, buttonBar is wired up to an IBOutlet as searchWhat and I can talk to this object from within the mapview's controller class.

如果用户在 Tab 1 中点击一个单元格,我希望它切换到 Tab 2 并填充 searchWhat.text,然后执行搜索代码,就像有人自己输入搜索一样.

If the user is in Tab 1 and taps a cell, I want it to switch to Tab 2 and populate the searchWhat.text and then execute the search code as if someone had typed in the search themselves.

我遇到的问题是视图的加载顺序和填充顺序.

What i'm having trouble with is the order of load and populate on a view.

我可以毫无问题地从第一个选项卡访问第二个选项卡,并使其显示如下内容:

I can access the 2nd tab from the 1st without any problem and get it to appear with something like:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Quick Category cell tapped at row %d", indexPath.row);    
    self.tabBarController.selectedIndex = 1; // change to the search view controller
    //[self.tabBarController.selectedViewController viewDidAppear:YES];
    UINavigationController *nav = (UINavigationController *)self.tabBarController.selectedViewController;
    SearchViewController *srch = [nav.viewControllers objectAtIndex:0];
    //NSLog(@"%@", [srch description]);
    [srch queueSearchByType:kSearchTypeQuickCategories withData:[catList objectAtIndex:indexPath.row]];
    [srch viewDidAppear:YES];
}

不要担心 catList 和 SearchViewController,它们是存在的,这个位可以用来切换标签页.

Don't worry about catList and SearchViewController, they exist and this bit works to switch tabs.

这里的问题是,如果用户启动应用程序并选择选项卡 1 中的一个项目,选项卡 2 会出现,但搜索显示文本的值没有设置 - 因为在另一个线程中调用了 viewDidLoad 和 viewDidAppear,所以执行 queueSearchByType:withData: 在视图仍在加载和设置时被调用.

Here's the problem though, if the user starts the application and selects an item in tab 1, tab 2 appears but the values of the search display text don't get set - because viewDidLoad and viewDidAppear are called in another thread so the execution of queueSearchByType:withData: gets called while the view is still loading and setting up.

如果用户选择标签 2(因此初始化子视图),然后选择标签 1 和一个项目,它可以填充搜索显示文本.

If the user selects tab 2 (therefore initialising the subview) and then selects tab 1 and an item, it can populate the search display text.

我不能只是更改选项卡的顺序,以便 tab2 是第一个,因此将其子视图加载到导航栏,因为项目规范首先是类别搜索.

I can't just change the order of the tabs so that tab2 is first and therefore loads it's subviews to the navigation bar as the project specification is category search first.

我是否遗漏了一些非常简单的东西?我需要做的是在调用 queueSearchByType:withData: 之前等待第二个选项卡完全出现: - 有没有办法做到这一点?

Have I missed something very simple? What I need to do is wait for the second tab to fully appear before calling queueSearchByType:withData: - is there a way to do this?

目前,我已经实现了队列搜索,检查队列搜索方法,这似乎有点啰嗦.

At the moment, i've implemented a queue the search, check for a queue search approach, this seems to be a bit long winded.

推荐答案

好吧,我不喜欢回答我自己的问题,但看起来我的恐惧是对的,基本上如果你想要一个自定义视图的 UINavigationItem(即,将搜索栏和各种其他按钮放在导航控制器上)并能够切换到标签栏控制器上的另一个标签并从其填充它们,然后您需要将子视图放在它自己的类中,该类是 UIViewController 的子类然后让代表团成为你的朋友(已经是),我已经提供了一个例子,以防有人需要重复它,我已经把它放在我的博客上.

Ok, I don't like answering my own question but it appears my fears were right, basically if you want a UINavigationItem that is a custom view (ie, to put a search bar and various other buttons up on the nav controller) and be able to switch to and populate them from another tab on a tab bar controller, then you need to put the subview in it's own class which is a subclass of UIViewController and then make delegation your friend (which it already is), i've provided an example in case anybody needs to repeat it which i've put on my blog HERE.

http://www.jamesrbrindle.com/developer/ios-developer/howto-add-a-custom-uinavigationitem-to-a-uinavigationcontroller-with-delegation.htm

如果有人不同意并认为这可以更简单,请告诉我或评价这篇文章

If anyone disagrees and thinks this can be simpler, please let me know or rate this post

这篇关于iOS:从 UITabBar/UINavigationController 应用程序的视图中设置笔尖子视图中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆