gpt4 book ai didi

IOS 如何更改现有 UI 以使用新的导航 Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:40 25 4
gpt4 key购买 nike

好的,我遇到了麻烦。

我用一个名为 MainView 的 UITableViewController 自定义类启动了一个应用程序。

在界面生成器中,我修改了 View ,以便在顶部有一个文本框和一个按钮以及一个 UITableView。将数据源和委托(delegate)连接到 MainView 类,并在所有代码中编程以使用文本字段作为搜索字段,将按钮作为搜索触发器,然后在适当的委托(delegate)方法中编程以填充 UITableView。这非常有效。

现在下一步是使用

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
方法能够显示带有与所选行相关的链接的 webview。所以阅读我发现我需要添加一个 UINavigationController 到组合中(以便获得工具栏和导航栏等。)。

现在我试了这个:从 Interface builder 添加一个导航 Controller ,并连接到 appdelegate 和一个 outlet


#import

@interface ComparateurAppDelegate : NSObject {
UIWindow *window;
UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

然后在执行

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {<br/>
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
}

这个启动正常,和以前一样,但我没有我应该有的顶部栏。另外,当我尝试在其中推送新 View 时,它什么也不做。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewController *wvc = [[WebViewController alloc] initWithNibName:@"WebViewController.nib" bundle:nil];<p></p>

<pre><code>[self.navigationController pushViewController:wvc animated:YES];

[wvc release];
}
</code></pre>

<p></p>
我知道代码正在运行,因为我 nslog 它。但什么也没有发生。 WebViewController.nib 是我创建的 nib 文件(现在是空的),所以我用 UIwebview 填充它。

我现在的猜测是 View 层次结构没有设置好。

所以我尝试了一些我记不太清楚的事情,并在我已经拥有的窗口顶部找到了工具栏,但是所有内容都无法访问(比如工具栏是一个模态对话框,我无法使用底部一个,或者像一个透明 View ,你可以在下面看到堆叠的第一个窗口)。我还尝试像这样在 appDelegate 中以编程方式创建 UINavigation Controller


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.
UIViewController *rootController = [[MainView alloc]init];
navigationController = [[UINavigationController alloc]initWithRootViewController:rootController];
[rootController release];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

[window addSubview:navigationController.view];
[window makeKeyAndVisible];

return YES;
}

我得到的只是一个用于界面的空 UITableView,而不是 MainView.nib(其类设置为 MainView)。

长话短说:有一个正在运行的应用程序,想要添加详细 View ,并且需要修改为 UINavigationController 但似乎无法找到正确的方法。

提前致谢,抱歉发了这么长的帖子。

最佳答案

尝试改变这个:

UIViewController *rootController = [[MainView alloc]init];

对此:

UIViewController *rootController = [[MainView alloc]initWithNibName:@"MainView" bundle:nil];

关于IOS 如何更改现有 UI 以使用新的导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4624819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com