简体   繁体   English

我可以将pushViewController与UISegmentedControl一起使用吗?

[英]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.

相关问题 为什么我不能将pushViewController与UIButton一起使用? - Why can't I use pushViewController with UIButton? iOS如何将pushviewcontroller与NavigationController一起使用(Objective-c) - iOS How can I use pushviewcontroller with NavigationController(Objective - c) 在哪里创建navigationController,以便我可以使用pushViewController函数 - Where to create navigationController so that I can use the pushViewController function iOS - 为什么我不能以两次相同的方式使用pushViewController? - iOS - Why can't I use pushViewController the same way twice? 如何禁用 UISegmentedControl? - How can I disable a UISegmentedControl? 如何在UISegmentedControl上重新加载tableView重新加载,单击为pushviewcontroller - How to animate tableView reload on UISegmentedControl click as pushviewcontroller 如何在iPhone / iPad中解除pushViewController? - How can I dismiss a pushViewController in iPhone/iPad? 如何使用UISegmentedControl切换视图? - How do I use a UISegmentedControl to switch views? 如何设置 UISegmentedControl 的默认状态? - How can I set the default state of a UISegmentedControl? 无法弄清楚如何在UIViewController中一起使用UINavigationControllerDelegate和pushViewController - Can't figure out how to use UINavigationControllerDelegate and pushViewController together in a UIViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM