【问题标题】:pushViewController not work with .xib filepushViewController 不适用于 .xib 文件
【发布时间】:2015-08-26 11:29:56
【问题描述】:

** 在 ** Discover.m 中

AgendaListPage *controller1 = [[AgendaListPage alloc]initWithNibName:@"AgendaListPage" bundle:nil];
    controller1.title = @"Page1";
    MissedDataListPage *controller2 = [[MissedDataListPage alloc]initWithNibName:@"MissedDataListPage" bundle:nil];
    controller2.title = @"Page2";

** In ** AgendaListPage.m

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.tableView){
 
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        HastagScreenTablePage *myControllerHastag = [storyboard instantiateViewControllerWithIdentifier:@"hastagScreen"];
        myControllerHastag.detailModalForHastag = @[[getTopHastagObject[indexPath.row] gethastagName]];
        [self.navigationController pushViewController: myControllerHastag animated:YES];
    }
}

我使用https://github.com/uacaps/PageMenu API Obj-C 版本。

我尝试了所有方法,但在选择行时页面不会改变。有什么想法吗?

编辑:

我这样修改代码

 HastagScreenTablePage *myControllerHastag = [self.storyboard instantiateViewControllerWithIdentifier:@"hastagScreen"];
 myControllerHastag.detailModalForHastag = @[[getTopHastagObject[indexPath.row] gethastagName]];
 FirstNavControllerPage *navigationController = [[FirstNavControllerPage alloc] initWithRootViewController:myControllerHastag];
 [self.navigationController pushViewController: navigationController animated:YES];

FirstNavControllerPage 是一个 UINavigationController

现在错误:Application tried to push a nil view controller on target <FirstNavControllerPage: 0x13659d5c0>.

编辑:

【问题讨论】:

  • self.navigationController nil?
  • 是的,你是正确的 self.navigationController 是 nil 我该如何解决?我编辑问题
  • 您应该在创建 AgendaListPage 对象时以编程方式将 AgendaListPage 控制器添加到导航控制器。例如'AgendaListPage *obj = [[AgendaListPage alloc]init]; UINavigationController *navController = [UINavigationController alloc]initWithRootViewController:obj;'
  • HastagScreenTablePage *myControllerHastag = [self.storyboard instantiateViewControllerWithIdentifier:@"hastagScreen"]; myControllerHastag.detailModalForHastag = @[[getTopHastagObject[indexPath.row] gethastagName]]; FirstNavControllerPage *navigationController = [[FirstNavControllerPage alloc] initWithRootViewController:myControllerHastag]; [self.navigationController pushViewController: navigationController animated:YES]; 我这样改代码还是不行
  • 不,我说的是 HastagScreenTablePage,我说的是我认为的当前控制器,即 AgendaListPage 你应该在 Navigationcontroller 中添加这个 AgendaListPage 控制器

标签: ios objective-c storyboard pushviewcontroller


【解决方案1】:

对于 Xib,您不需要创建情节提要对象

只是控制器分配初始化工作

HastagScreenTablePage *myControllerHastag = [[HastagScreenTablePage alloc]init];
[self.navigationController pushViewController:myControllerHastag animated:YES];

【讨论】:

    【解决方案2】:

    您没有在情节提要中添加导航控制器。对?如果是这样,您将得到“self.navigation == nil”。首先添加导航控制器,然后设置根视图控制器。然后你的 pushViewController 将得到它的实例并工作。

    【讨论】:

    • HastagScreenTablePage *bbp = [[HastagScreenTablePage alloc]initWithNibName:@"Main" bundle:nil]; UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp]; [self.navigationController pushViewController:passcodeNavigationController animated:YES]; 喜欢这个?
    • 右键单击并从导航控制器拖动到 YourFirstViewController 然后您将看到许多选项可供选择。然后选择“根视图控制器”
    • 但我使用 .xib 我如何在 .xib 中做到这一点?
    • 我知道如何添加导航。控制器老兄。但是这个页面使用.xib 我会添加图片请检查
    • 我添加图像导航控制器连接viewcontroller这个控制器调用nibs。
    【解决方案3】:

    确保在故事板文件中为 UIViewController 设置标识符(在您的情况下为“hastagScreen”),可能以下代码返回 nil。

    HastagScreenTablePage *myControllerHastag = [self.storyboard instantiateViewControllerWithIdentifier:@"hastagScreen"]; // myControllerHastag might be nil.
    

    【讨论】:

    • HastagScreenTablePage 在 Discover.m 检查图像中没有 viewController addSubview
    • instantiateViewControllerWithIdentifier 会给你一个 viewcontroller 对象,你将它分配给HastagScreenTablePage (“HastagScreenTablePage has not got viewController”),我认为它是一个UIView,完全错误
    • 其实 HastagScreenTablePage 有 viewcontroller 但是在 .xib 所以我不能添加导航控制器...
    • 那么不需要导航控制器,使用Rahul Shirphule建议的代码
    猜你喜欢
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-21
    • 2013-08-04
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多