【发布时间】:2013-03-31 11:47:46
【问题描述】:
我已经搜索和试验了一段时间,但我就是不知道我做错了什么。
我想制作一个带有菜单的应用程序,从该菜单中,您可以访问带有标题栏的TableViewcontroller。我发现,为了得到这个标题栏,你需要将UITableViewController“插入”到UINavigationController中。这就是我卡住的地方。
暂时不要介意/忘记应用程序中的菜单,因为我知道当用户点击按钮时如何切换视图控制器。
在我的 AppDelegate.m 中有:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
TableViewController *tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
self.navController = [[UINavigationController alloc] initWithRootViewController:tableView];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
在我的 AppDelegate.h 文件中:
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
UINavigationController *navcontroller;
}
@property (strong, nonatomic) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
我有 2 个分类器,UITableViewController 和 NavigationView。
在UITableViewController中,我做了一个叫tableRows的数组:
tableRows = [[NSArray arrayWithObjects:@"1", @"2", nil] init];
numberOfSectionsInTableView 设置为 1,numberOfRowsInSection 设置为 return tableRows.count;
我没有改动我的 NavigationView.m,只是我尝试在其中设置标题。
在我的NavigationView.xib 中,我尝试在UITableViewController 和UINavigationController 之间建立连接。
- 我添加了一个 NSObject,并将其类更改为 AppDelegate
- 我将 View 替换为
UIWindow并从我的AppDelegate.h给它 - 我添加了
UINavigationController和 将它与我的AppDelegate.h中的navController连接起来。 - 最后,我将 RootView 中的类从
UINavigationController到UITableViewController。
现在我的问题是,无论是否有 IB 中的连接,无论我尝试在表格或标题栏中更改什么,在我运行应用程序时它都不会改变。
有人知道我做错了什么吗?我使用的是 xcode 4.6,所以我检查过的很多教程都不是很有用,因为它们是用旧版本的 xcode 制作的。请帮助我,提前谢谢!
【问题讨论】:
-
如果可能的话,使用另一个带有 XIB 的 ViewController 并在 ViewController 中添加 tableView。您可能无法直接添加该 tableView。
-
很幸运不可能。当我这样做时,它也给出了一个问题:
loaded the "ViewController" nib but the view outlet was not set.'; -
它没有加载数据吧?
-
你在吗@JorisDijkstra,请回复
-
可能不是。我真的很想知道我做错了什么,因为当我开始在 SO 和其他网站上搜索其他问题时,这似乎是最简单的事情。在处理了一段时间没有任何结果之后,它开始让我绝望..
标签: iphone xcode ipad uinavigationcontroller uitableview