0

我正在为 ipad 和 iphone 实现 TabBar 应用程序。但在 IPAD 中,导航控制器不适用于表格单元格中的 ipad 笔尖。viewdid Load 方法不是为 ipad 调用的。但它适用于 iphone .. self.navigationController 对于 ipad 为 NULL 仅在我的班级中导航。帮我!!

我的代码如下:

//Connet.m:

if(i==1)
{
    TwitterController *tc;
    if ([self isPad]) {
    tc = [[TwitterController alloc] initWithNibName:@"TwitterController_ipad" bundle:nil];    
}
else
    tc = [[TwitterController alloc] initWithNibName:@"TwitterController" bundle:nil];

[self.navigationController pushViewController:tc animated:YES];        
NSLog(@"%@",self.navigationController);   /Problem ****NULL*****///////          


//TWITTER.m    
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            //Custom initialization
            self.navigationController.navigationBarHidden = YES;          
        }
    return self;
}  

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    NSString *urlAddress = @"https://twitter.com/UJUDGEIT1";
    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];
    //URL Request Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];   
    //Load the request in the UIWebView.
    [webv loadRequest:requestObj];
}
4

2 回答 2

0

皮尤什

你如何实现你的标签栏。使标签栏的每个控制器成为导航控制器。它可能会调用您的视图确实加载方法。

以下代码可能会对您有所帮助。它在标签栏上创建 2 个控制器。最后在它的根视图控制器。

-(void)createTabbar{
    NSMutableArray *controllers = [[NSMutableArray alloc] init];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

        //Controller 1
        PasswordVC *pvc = [[PasswordVC alloc] initWithNibName:@"PasswordVC" bundle:nil];
        UINavigationController *passwordNav = [[UINavigationController alloc] initWithRootViewController:pvc];
        passwordNav.navigationController.navigationBarHidden=YES;
        [controllers addObject:passwordNav];
        pvc.title = @"Password";
        [pvc release];

        [passwordNav release];

        //Controller 2
        SettingVC *SVC = [[SettingVC alloc] initWithNibName:@"SettingVC" bundle:nil];
        UINavigationController *settingNav = [[UINavigationController alloc] initWithRootViewController:SVC];
        settingNav.navigationController.navigationBarHidden=YES;
        [controllers addObject:settingNav];
        SVC.title = @"Settings";
        [SVC release];

        [settingNav release];    
    }
    else {         //ipad

    }

    _tabBarController = [[[UITabBarController alloc] init] autorelease];
    _tabBarController.delegate=self;
    _tabBarController.viewControllers = controllers;
    _tabBarController.customizableViewControllers = controllers;

    [UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_window cache:NO];
    _window.rootViewController = _tabBarController;

    [UIView commitAnimations];
}
于 2012-07-24T09:25:28.730 回答
0

试试下面的代码:

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    NSString *nibname=@"";
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){

        nibname=@"TwitterController_ipad";   
    }
    else{
        nibname=@"TwitterController"; 


    }
    TwitterController *view = [[TwitterController alloc] initWithNibName:nibname bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:view];

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

在您的应用委托类中编写此代码。该viewDidLoad方法被调用。

于 2012-07-21T11:58:29.967 回答