标签栏和导航控制器:我的Interface Builder接线出了什么问题? [英] Tab Bar and Nav Controller: Where did I go wrong in my Interface Builder wiring?
问题描述
我一直在使用Tab Bar项目类型的XCode和Interface Builder中的iPhone应用程序。在获得主题(业务部门)的表格视图工作正常后,我意识到我需要添加导航控件以允许用户钻入子主题(子部门)表。
I've been working on an iPhone application in XCode and Interface Builder of the Tab Bar project type. After getting a table view of topics (business sectors) working fine I realized that I would need to add a Navigation Control to allow the user to drill into a subtopics (subsectors) table.
作为一名绿色的Objective-C开发人员,这令人困惑,但我设法通过阅读各种文档来尝试一些不同的IB选项。我当前的设置是一个标签栏控制器,标签1作为导航控制器,标签2是一个普通视图,其中放置了一个表格视图。接线工作原理:我可以在选择表行时记录,并且我已准备好将新的View Controller推入堆栈,以便显示子视图Table View。
As a green Objective-C developer, that was confusing, but I managed to get it working by reading various documentation trying out a few different IB options. My current setup is a Tab Bar Controller with Tab 1 as a Navigation Controller and Tab 2 a plain view with a Table View placed into it. The wiring works: I can log when table rows are selected and I'm ready to push a new View Controller onto the stack so that I can display the subtopics Table View.
我的问题:由于某种原因,第一个选项卡的表视图是第二个选项卡的委托和dataSource。这对我来说没有意义,我无法弄清楚为什么这是唯一有效的设置。我有其他问题,我认为这是由愚蠢的布线引起的。
My problem: For some reason the first tab's Table View is a delegate and dataSource of the second tab. It doesn't make sense to me and I can't figure out why that's the only setup that works. I am having other problems that I believe are caused by the goofy wiring.
替代文字http://i43.tinypic.com/30nap85.jpg
以下是布线:
- 导航控制器(Sectors)是Tab Bar的
代表
- 导航栏是
a导航控制器代表
(部门) - 查看控制器(部门)有视图表视图
- 表视图(在导航中
控制器(扇区))是第一视图控制器的委托
(公司) - 表视图(在导航$中) b $ b Controller(Sectors))是First View Controller的数据源插座
(公司)
- Navigation Controller (Sectors) is a
delegate of Tab Bar
- Navigation Bar is a delegate of Navigation Controller (Sectors)
- View Contoller (Sectors) has a view of Table View
- Table View (in Navigation Controller (Sectors)) is a delegate of First View Controller (Companies)
- Table View (in Navigation Controller (Sectors)) is a dataSource outlet of First View Controller (Companies)
- First View Contoller(Sectors)有一个Table View视图
- 表视图(在First View Controller中) (公司))没有连接到数据来源插座并且不是代表
当我点击标签按钮并查看在Inspector中,我看到第一个选项卡正确连接到我的MainWindow.xib,第二个选项卡选择了一个名为SecondView.xib的笔尖。它位于MainWindow.xib的文件所有者中,我在.h中继承了UITableViewDataSource和UITableViewDelegate(以及UITabBarControllerDelegate),在.m中我实现了委托方法。
When I click the tab buttons and look at the Inspector I see that the first tab is correctly hooked up to my MainWindow.xib and the second tab has selected a nib called SecondView.xib. It's in the File's Owner of MainWindow.xib where I inherit UITableViewDataSource and UITableViewDelegate (and also UITabBarControllerDelegate) in the .h, and in the .m where I implement the delegate methods.
为什么此设置仅在我的第一个选项卡(View Controller(Sectors))中的Table View是第二个选项卡的委托和dataSource时有效?我很困惑:为什么不需要将它连接到可以看到表视图的导航控制器选项卡(导航控制器(扇区))?在第二个选项卡上看到的表视图既没有dataSource也没有委托。
Why does this setup only work when the Table View in my first tab (View Controller (Sectors)) is a delegate and dataSource of the second tab? I'm confused: why wouldn't it need to be hooked up to the Navigation Controller-enabled tab in which the Table View is seen (Navigation Controller (Sectors))? The Table View seen on the second tab has neither dataSource and is not a delegate.
alt text http://i40.tinypic.com/15ri1ig.jpg
替代文字http://i44.tinypic.com/2dwete9.jpg我无法获得pushViewController fire(self.navigationController不是nil但是新的View Controller仍然没有加载)我怀疑我需要解决这个IB布线问题才能解决为什么Nav Controller不会将新的View Controller推到叠加。
I'm having trouble getting a pushViewController to fire (self.navigationController is not nil but the new View Controller still doesn't load) and I suspect that I need to work out this IB wiring issue before I can troubleshoot why the Nav Controller won't push a new View Controller onto the stack.
if(nil == self.navigationController) { NSLog(@"self.navigationController is nil."); } else { NSLog(@"self.navigationController is not nil."); SectorList *subsectorViewController = [[SectorList alloc] initWithNibName:@"SectorList" bundle:nil]; subsectorViewController.title = @"Subsectors"; [[self navigationController] pushViewController:subsectorViewController animated:YES]; [subsectorViewController release]; }
推荐答案
跳出来的第一件事在我看来,你的Sectors选项卡的视图控制器是一个UIViewController,而不是UITableViewController。您应该删除整个视图控制器并从IB中的库中拖出UITableViewController并将其放在UINavigationController上。它将附带一个UITableView作为其视图,UITableViewController已经设置为该tableView的dataSource和委托。
The first thing that jumps out at me is that the view controller for your Sectors tab is a UIViewController, instead of a UITableViewController. You should just delete that whole view controller and drag a UITableViewController from your library in IB and drop it on your UINavigationController. It will come with a UITableView already hooked up as its view, with the UITableViewController already set as the dataSource and delegate for that tableView.
在你的NIB中有一个UITableViewController然后,您应该在检查器中将其类名更改为您在代码中实现的UITableViewController子类的名称。
Once you have a UITableViewController in your NIB, you should then change its class name in the inspector to the name of a UITableViewController subclass that you've implemented in code.
另一件事:当你声明你的表视图是一个数据源和是一个委托时,你有向后的dataSource和委托关系。只是为了澄清:
One other thing: You have the dataSource and delegate relationships backwards when you state that your table view "is a dataSource," and "is a delegate". Just to clarify:
- 一个tableView有一个dataSource属性,它指向一个实现UITableViewDataSource协议的对象(通常是一个UITableViewController子类实例) 。
- 一个tableView有一个委托属性,它指向一个实现UITableViewDelegate协议的对象(通常是同一个UITableViewController子类实例)。
- UITableViewController类实现UITableViewDataSource和UITableViewDelegate协议。正确配置后,您的自定义UITableViewController子类是其tableView的dataSource和委托。
这篇关于标签栏和导航控制器:我的Interface Builder接线出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 导航栏是