故事板中创建的TabbarController无法以编程方式更改视图 [英] Created TabbarController in Storyboard can't change view programmatically

查看:109
本文介绍了故事板中创建的TabbarController无法以编程方式更改视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建 tabbarcontroller 作为splitview控制器的详细视图。我可以通过在模拟器上单击 item1 item2 图标来更改视图,但无法以编程方式更改视图。

Created a tabbarcontroller as a detail view of splitview controller. I can change the view by clicking item1, item2 icons on simulator, but can not change view programmatically.

当我尝试在<$中打印 viewcontrollers 时,我得到 null c $ c> nslog 。
在MasterView中:

I am getting null when try to print viewcontrollers in nslog . In MasterView:

@property (strong, nonatomic) TabBarRootViewController *detailViewController;
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.detailViewController=[[TabBarRootViewController alloc] init];
//tried also
self.detailViewController = (TabBarRootViewController *)[self.splitViewController.viewControllers objectAtIndex:1];

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //this sends object info to detail
    if (indexPath.section==0) {
        //send row number
       NSNumber *i = [NSNumber numberWithInteger:indexPath.row];
        NSLog(@"Selected index %@",i);

        self.detailViewController.detailItem = i;
    }
}

详细信息(Tabbar):

In detail(Tabbar):

@property (strong, nonatomic) id detailItem;

if (self.detailItem) {
    NSInteger i=[self.detailItem integerValue];
    NSLog(@"recieved integer is %i",i);

    //tried this
    self.tabBarController.selectedIndex=i;
    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:i];

    //list of viewcontrollers
    NSArray *array;
    array = [[self tabBarController] viewControllers];
    NSLog(@"array %@",array);

}

NSLOG:
recieved integer is 1
array (null)

如何以编程方式更改视图?

How can I change the view programmatically?

谢谢,

S

推荐答案

问题是无法获得指向theTabbarcontroller的确切指针。

The problem was not able to get the exact pointer to theTabbarcontroller.

我删除了导航控制器并只留下了tabbar controller.Also在主视图中删除了 [topcontroller] 请求appdelegate。

I removed the navigation controller and left only tabbar controller.Also removed the [topcontroller] requests in master view and appdelegate.

所以最终工作代码是

appdelegate:

appdelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

masterview:
- (void)viewDidLoad

masterview: - (void)viewDidLoad

{
    [super viewDidLoad];

    self.detailViewController = (TabBarRootViewController *)[self.splitViewController.viewControllers objectAtIndex:1];

}

tabbarcontroller(详情控制器)中的

in tabbarcontroller (detail controller)

@property (strong,nonatomic) UITabBarController *rootController;

        self.rootController= (TabBarRootViewController *)[self.splitViewController.viewControllers objectAtIndex:1];
        self.rootController.selectedIndex=i;

这篇关于故事板中创建的TabbarController无法以编程方式更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆