Iphone 导航pushview控制器不工作
我正在为ipad和iphone实现TabBar应用程序。但在IPAD中,导航控制器不适用于表单元格中的IPAD nib。viewdid加载方法不适用于ipad。 但它在iphone上运行良好。。 self.navigationController仅在我的类中对ipad进行导航时为空。 救救我 我的代码如下:Iphone 导航pushview控制器不工作,iphone,objective-c,ios,cocoa-touch,ios5,Iphone,Objective C,Ios,Cocoa Touch,Ios5,我正在为ipad和iphone实现TabBar应用程序。但在IPAD中,导航控制器不适用于表单元格中的IPAD nib。viewdid加载方法不适用于ipad。 但它在iphone上运行良好。。 self.navigationController仅在我的类中对ipad进行导航时为空。 救救我 我的代码如下: //Connet.m: if(i==1) { TwitterController *tc; if ([self isPad]) { tc = [[TwitterCo
//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];
}
请尝试以下代码:
(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
方法。piyush
如何实现选项卡栏。
将选项卡栏的每个控制器设置为导航控制器。它可能称为您的视图加载方法
下面的代码可能对您有所帮助。它在选项卡栏上创建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];
}
但所有的导航控制器都在工作。只有在我的this类中,它才不起作用..我实现了TabBar应用程序请参见我的代码,我在coonnect.m中为self.navegationController获取了NULL,但仅在IPAD中。该应用程序在iphone上运行良好。。