将 TableViewController 添加到现有项目

发布于 2024-11-19 18:23:15 字数 1361 浏览 3 评论 0原文

我有一个现有的 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 技术交流群。

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

发布评论

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

评论(2

浪推晚风 2024-11-26 18:23:15
- (void)LetsGoButtonTouched {
TableViewController *tableViewController = [[TableViewController alloc] init];
[[self navigationController] pushViewController:tableViewController animated: YES];
}

尝试一下。这就是你想要发生的事情吗?

如果是这样,我所做的就是创建表视图控制器的一个新实例并将其推送。在您的原始代码中,您试图推动应用程序委托,但这是无法完成的;应用程序委托不是视图控制器。 TableViewController 是 UITableViewController 的子类,因此您可以将其用于 pushViewController: 方法 - 并且表格视图将出现在屏幕上。

- (void)LetsGoButtonTouched {
TableViewController *tableViewController = [[TableViewController alloc] init];
[[self navigationController] pushViewController:tableViewController animated: YES];
}

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.

荒人说梦 2024-11-26 18:23:15

谢谢本杰明。出色的。但它并没有完全按照这种方式工作——经过两天的艰苦努力,我设法让它运行起来。对于那些感兴趣的人,这就是我所做的:

  1. 如果您想添加带有 NavigationController 的现有 TableViewController,您只需要 TableViewController 和 DetailViewController 文件。忘记 AppDelegate。

  2. 执行两次新文件 ->将现有代码子类化并分别复制到相同的 TableViewController .h/.m/.xib - 和 DetailViewController .h/.m/.xib 中。

  3. 当您进行方法调用时,您必须集成 TableViewController 和 NavigationController - 如下所示:

    - (void)LetsGoButtonTouched {
    TableViewController *tvc = [[[TableViewController alloc] init] autorelease];
    UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:tvc]autorelease];
    [自我呈现ModalViewController: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:

  1. If you want to add an existing TableViewController with a NavigationController you'll only need the TableViewController and the DetailViewController files. Forget the AppDelegate.

  2. Do twice new file -> Subclass and copy your existing code into identical TableViewController .h/.m/.xib - and DetailViewController .h/.m/.xib respectively.

  3. When you make the method call you have to integrate both the TableViewController and the NavigationController - like this:

    - (void)LetsGoButtonTouched {
    TableViewController *tvc = [[[TableViewController alloc] init] autorelease];
    UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:tvc]autorelease];
    [self presentModalViewController:navigationController animated:YES];
    

By the way, this question gave me the hint:
Add a UINavigationBar to a UITableViewController without a UINavigationController

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