pushViewController不能与.xib文件一起使用

时间:2015-08-26 11:29:56

标签: ios objective-c storyboard pushviewcontroller

** ** Discover.m

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

**在** 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>.

编辑:

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:0)

对于Xib,您不需要创建故事板对象

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

确保为故事板文件中的UIViewController设置标识符(&#39; hastagScreen&#39;),可能是以下代码返回nil。

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

replace YOUR_ID with hastagScreen