[英]Can I use pushViewController with UISegmentedControl?
I want to use pushViewController with UIsegmentedController to push to other view and xib. 我想将pushViewController与UIsegmentedController一起使用以推送到其他视图和xib。 Can I do that in xcode 4 ??? 我可以在xcode 4中做到吗? If I can , Could you guide me please ? 如果可以的话,你能指导我吗?
Here is some code that I try.But won't work. 这是我尝试的一些代码,但是不起作用。
-(IBAction) segmentedControlIndexChanged:(id)sender
{
if ([sender selectedSegmentIndex] == 0)
{
BDshelveController *shelve_page = [[BDshelveController alloc] initWithNibName: @"BDshelveController" bundle:nil];
}
else if([sender selectedSegmentIndex] == 2)
{
BDlibraryController *lib_page = [[BDlibraryController alloc] initWithNibName:@"BDlibraryController" bundle:nil];
[self.navigationController pushViewController:lib_page animated:YES];
}
}
yes you can, these are the things you could check 是的,您可以,这些是您可以检查的
you missed segmentedIndex=1 in your code. 您错过了代码中的segmentedIndex = 1。
you missed to call pushViewController when selected segment=0 您未选择选定的细分= 0时调用pushViewController
Or it is more likely that self.NavigatonController is nil 或者更可能self.NavigatonController为nil
Your segmented control has not been connected valuechange to your action 您的分段控件尚未关联到将值更改为您的操作
If self.navigationController is nil, it depends on how you initialize your app, if your app is navigation bar driven, then this code in your AppDelegate should resolve the issue: 如果self.navigationController为nil,则取决于您如何初始化应用程序,如果应用程序是导航栏驱动的,则AppDelegate中的以下代码应可以解决问题:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:yourRootViewController]; // <-- depends if you have storyboards, xib etc...you should this already initialized
[self.window addSubview:navController.view];
[navController release]; // <-- depends if you have ARC
[self.window makeKeyAndVisible];
return YES;
}
Otherwise I suppose you can initialize it where you are, by giving self as root controller. 否则,我想您可以通过将self作为根控制器来将其初始化为您所在的位置。
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.