将 TableViewController 添加到现有项目
我有一个现有的 TableViewController 如下
// TableViewController.h
@interface TableViewController : UITableViewController { NSArray *dataArray; }
@property (nonatomic, retain) NSArray *dataArray;
和一个 navAppDelegate - 具体来说:
// navAppDelegate.h
#import <UIKit/UIKit.h>
@interface navwAppDelegate : NSObject
<UIApplicationDelegate, UINavigationControllerDelegate> {
UIWindow *window;
IBOutlet UINavigationController *navigationController;}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
// navAppDelegate.m
#import "navAppDelegate.h"
@implementation navigationtableviewAppDelegate
@synthesize window, navigationController;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window makeKeyAndVisible];
[window addSubview:[navigationController view]];
}
现在,我只是将文件添加到现有项目中,除了我将 (void)applicationDidFinishLaunching{} 的内容放入 (void)viewDidLoad{} 中,因为它是从现在开始查看而不是窗口(对吗?)。它不起作用,我的猜测是我必须将上面的所有窗口调用更改为视图?我在这里犯了什么根本错误? 我正在拨打电话
// StartOffHere.m
- (void)LetsGoButtonTouched {
navAppDelegate *newview = [[navAppDelegate alloc] initWithNibName:nil bundle:nil]; // I get a SIGABRT here
[[self navigationController] pushViewController: newview animated: YES];
}
I have an existing TableViewController as follows
// TableViewController.h
@interface TableViewController : UITableViewController { NSArray *dataArray; }
@property (nonatomic, retain) NSArray *dataArray;
And a navAppDelegate - to be specific:
// navAppDelegate.h
#import <UIKit/UIKit.h>
@interface navwAppDelegate : NSObject
<UIApplicationDelegate, UINavigationControllerDelegate> {
UIWindow *window;
IBOutlet UINavigationController *navigationController;}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
// navAppDelegate.m
#import "navAppDelegate.h"
@implementation navigationtableviewAppDelegate
@synthesize window, navigationController;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window makeKeyAndVisible];
[window addSubview:[navigationController view]];
}
Now, I simply added the files to an existing project, except I put the content of (void)applicationDidFinishLaunching{} in a (void)viewDidLoad{} since it's a view from now on and not a window (right?). It doesn't work and my guess is that I have to change all the window calls from above to a view? What am I making here fundamentally wrong?
I'm making a call from
// StartOffHere.m
- (void)LetsGoButtonTouched {
navAppDelegate *newview = [[navAppDelegate alloc] initWithNibName:nil bundle:nil]; // I get a SIGABRT here
[[self navigationController] pushViewController: newview animated: YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下。这就是你想要发生的事情吗?
如果是这样,我所做的就是创建表视图控制器的一个新实例并将其推送。在您的原始代码中,您试图推动应用程序委托,但这是无法完成的;应用程序委托不是视图控制器。 TableViewController 是 UITableViewController 的子类,因此您可以将其用于 pushViewController: 方法 - 并且表格视图将出现在屏幕上。
Try that. Is that what you wanted to happen?
If so, what I have done is created a new instance of your table view controller and pushed that. In your original code, you were trying to push on the app delegate which cannot be done; the app delegate is not a view controller. TableViewController, your subclass of UITableViewController, is though, so you can use this for the pushViewController: method - and the table view will appear on screen.
谢谢本杰明。出色的。但它并没有完全按照这种方式工作——经过两天的艰苦努力,我设法让它运行起来。对于那些感兴趣的人,这就是我所做的:
如果您想添加带有 NavigationController 的现有 TableViewController,您只需要 TableViewController 和 DetailViewController 文件。忘记 AppDelegate。
执行两次新文件 ->将现有代码子类化并分别复制到相同的 TableViewController .h/.m/.xib - 和 DetailViewController .h/.m/.xib 中。
当您进行方法调用时,您必须集成 TableViewController 和 NavigationController - 如下所示:
顺便说一句,这个问题给了我提示:
将 UINavigationBar 添加到没有 UINavigationController 的 UITableViewController
Thanks Benjamin. Excellent. But it didn't work quite that way though - after two hard days I managed it to run. For those who are interesed, here's what I did:
If you want to add an existing TableViewController with a NavigationController you'll only need the TableViewController and the DetailViewController files. Forget the AppDelegate.
Do twice new file -> Subclass and copy your existing code into identical TableViewController .h/.m/.xib - and DetailViewController .h/.m/.xib respectively.
When you make the method call you have to integrate both the TableViewController and the NavigationController - like this:
By the way, this question gave me the hint:
Add a UINavigationBar to a UITableViewController without a UINavigationController