为什么 self.navigationController PushViewController 不起作用?

发布于 2024-10-03 10:52:14 字数 1128 浏览 2 评论 0原文

我有一个

UIViewController-> UINavigationBar + UITableView

只是更多的解释,

我通过 UIBuilder 做到了。

1:使用 XIB 文件创建了一个新的 UIViewController
2:使用UIBuiler我放置了一个UINavigationController
3:然后我将UITableView放在navigationBar下面 所以它给了我..

A:UIViewController-> UINavigationBar + UITableView

现在我正在从运行良好的 Web 服务加载 UITableView 中的数据。

我再次使用 sam 配置制作了一个 xib

B:UIViewController-> UINavigationBar + UITableView

所以现在当我尝试使用下面的代码将视图 B 推到视图 A 上时...它根本不起作用...

SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil];

[self.navigationController pushViewController:siteViewController animated:YES];

当我检查 UINavigationController *nav = self.navigation

nav 是 0x0也就是说我假设 NIL。

谁能告诉我这里出了什么问题..为什么为零...我怎样才能让它工作..

非常感谢....我真的很感激任何帮助

I have a

UIViewController-> UINavigationBar + UITableView

Just a bit more explanation

I made it through UIBuilder..

1: Created a New UIViewController with XIB-file
2: Using UIBuiler i put a UINavigationController
3: Then i put UITableView underneath the navigationBar
so it gave me..

A: UIViewController-> UINavigationBar + UITableView

Now i am loading the data in UITableView from a Webservice which is working fine.

I again made a xib with sam config which is

B: UIViewController-> UINavigationBar + UITableView

So now when i try to push view B on view A using below code...it wont at all work...

SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil];

[self.navigationController pushViewController:siteViewController animated:YES];

When i checked the UINavigationController *nav = self.navigation

nav is 0x0 that is i assume NIL.

Can anybody tell me whats wrong in here.. why is it nil...and how can i make it work..

Thanks a Lot....I would really appreciate any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

笔芯 2024-10-10 10:52:14

在 UIBuilder 中,验证文件所有者是否引用了 UINavigationController。

In UIBuilder verify that UINavigationController is referenced by the File's owner.

樱娆 2024-10-10 10:52:14

明白了。

我稍微改变了架构。

我用它的 xib 创建了一个新的 UIViewController 类。并编码了新的 UINavigationController。

- (void)viewDidLoad {
[super viewDidLoad];
    UINavigationController *navigationController
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];   


switch (whichViewController) {
    case 1:
        viewController = [[xxxx alloc] init];           
        break;
    case 2:
        viewController = [[xxx1 alloc] init];           
        break;
    default:
        break;
}

[navigationController pushViewController:viewController animated:NO];
[viewController release];

}

并在 Switch 语句中推送视图......

我希望这是有道理的......

谢谢 jamihash

Got it.

I changed the Architecture a little bit.

I made a New UIViewController class with its xib. And coded new UINavigationController.

- (void)viewDidLoad {
[super viewDidLoad];
    UINavigationController *navigationController
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];   


switch (whichViewController) {
    case 1:
        viewController = [[xxxx alloc] init];           
        break;
    case 2:
        viewController = [[xxx1 alloc] init];           
        break;
    default:
        break;
}

[navigationController pushViewController:viewController animated:NO];
[viewController release];

}

And pushing the view in the Switch Statement....

I hope this makes sense ......

Thanks jamihash

叹倦 2024-10-10 10:52:14

那么您要将 tableview 添加到导航控制器吗?方法如下:

tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

navigationController = [[UINavigationController alloc] init];

[navigationController pushViewController:tableView animated:NO];

tableview 作为根视图添加到导航控制器中。然后在选择一行时,如果您希望推送另一个视图控制器,请使用

self.navigationController pushViewController: newViewController animated:YES]; 

didSelectRowAtIndex 方法内部。

注意:其 UITableViewController *tableView 和 UINavigationController *navigationController 通过声明。因此,请为您的表进行相应的编码。

So you are adding the tableview to the navigation controller right? This is how:

tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

navigationController = [[UINavigationController alloc] init];

[navigationController pushViewController:tableView animated:NO];

The tableview gets added as the rootview to the navigation controller. And then on selecting a row if you wish to push another viewcontroller use the

self.navigationController pushViewController: newViewController animated:YES]; 

inside the didSelectRowAtIndex method.

NOTE: its UITableViewController *tableView and UINavigationController *navigationController by declaration. So code accordingly for your table.

溺渁∝ 2024-10-10 10:52:14

为什么UIViewController-> UINavigationBar + UITableView ?

我建议你另一种方法
->UITableViewController A ->;嵌入导航控制器,然后在填充表格视图后,您可以将数据传递给
->UITableViewController B 通过
[[自我故事板]instantiateViewControllerWithIdentifier:@"ControllerB"];

然后,在故事板中,放置一个 tableView B 并在 Identity->storyboard Id 中放置一些 id。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath
{
NSString *sUrl= @"<#string#>";
if (indexPath.row == 0) sUrl= @"http://www.apple.com/";
if (indexPath.row == 1) sUrl= @"http://www.google.com/";
if (indexPath.row == 2) sUrl= @"http://www.times.uk/";

NSMutableArray *selectedObject = [arrayOpenMale objectAtIndex:0];
NSLog(@"%@ is the selected object.",selectedObject);

SeriesAdetailVC *dvc = [[self  storyboard]instantiateViewControllerWithIdentifier:@"DetailView"];
dvc.strings7 = [NSURL URLWithString:sUrl];

[self.navigationController pushViewController:dvc animated:YES];

}

希望有帮助

why UIViewController-> UINavigationBar + UITableView ?

I suggest you another approach
->UITableViewController A -> Embedded with a Navigation Controller, then after populate tableview you can pass data to
->UITableViewController B by
[[self storyboard]instantiateViewControllerWithIdentifier:@"ControllerB"];

then, in storyboard, drop a tableView B and in Identity->storyboard Id put some id.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath
{
NSString *sUrl= @"<#string#>";
if (indexPath.row == 0) sUrl= @"http://www.apple.com/";
if (indexPath.row == 1) sUrl= @"http://www.google.com/";
if (indexPath.row == 2) sUrl= @"http://www.times.uk/";

NSMutableArray *selectedObject = [arrayOpenMale objectAtIndex:0];
NSLog(@"%@ is the selected object.",selectedObject);

SeriesAdetailVC *dvc = [[self  storyboard]instantiateViewControllerWithIdentifier:@"DetailView"];
dvc.strings7 = [NSURL URLWithString:sUrl];

[self.navigationController pushViewController:dvc animated:YES];

}

hope help

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