0

我在iOS的编程很新。视图切换到另一个视图上的故事板

我所试图做的是:

我有一个故事板的一些看法,我想通过程序的视图之间进行切换。例如,一个按钮被按下时,我调用一个方法,我想在这里更改视图(我可以调用成功的方法)。按钮也以编程方式在不同位置创建。

我已搜查,我想这与NavigationController发生。我有一个我创建的导航控制器,如下所示:menu Editor -> Embed In -> NavigationController。我怎么能用这个NavigationController做这个?

@Madhu和@Dilip,我发现xib递交类

icerik *secondViewController = [[icerik alloc] initWithNibName:@"icerik" bundle:nil]; 

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 
    navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; 
    navigationController.topViewController.title = @"SecondViewController"; 

    //[self presentModalViewController:navigationController animated:YES]; 

    if([self respondsToSelector:@selector(presentViewController:animated:completion:)]) 
     [self presentViewController:navigationController animated:YES completion:^{/* done */}]; 
    else if([self respondsToSelector:@selector(presentViewController:animated:)]) 
     [self presentModalViewController:navigationController animated:YES]; 

的解决方案我有一个名为icerik XIB文件中的类,我解决了它这样的。它是开放的,但当我想回头时,我能做什么?

+1

你想要的是,当用户点击btn时,他将从当前视图控制器转到另一个视图控制器,对吧? – Dilip 2013-02-19 12:25:18

+0

是的,我想改变使用故事板的两个viewcontrollers。 – ozmuhammed 2013-02-19 19:18:58

回答

0

您可以创建BTN使用此代码:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self action:@selector(aMethod) forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Show View" forState:UIControlStateNormal]; 
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); 
[self.view addSubview:button]; 

和走向另一个VC使用这个代码,如果你想要导航栏:

-(void)aMethod 
{ 
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:SecondViewController]; 
    navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; 
    navigationController.topViewController.title = @"SecondViewController"; 

    [self presentModalViewController:navigationController    animated:YES]; 
} 

否则,使用此代码:

-(void)aMethod 
{ 
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

    [self presentModalViewController:secondViewController   animated:YES]; 
} 

而对于回来弗里斯特VC弗洛姆第二VC在第二VC添加此代码。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(backAction:)]; 
    self.navigationItem.leftBarButtonItem = closeButton; 
} 
- (void)backAction:(id)sender { 
    [self dismissModalViewControllerAnimated:NO]; 
} 
+0

我改变了问题,你能再请看看:) – ozmuhammed 2013-02-19 19:48:43

+0

@ozmuhammed现在检查我编辑了我的答案。 – Dilip 2013-02-20 04:44:49

+0

太感谢你了,效果不错 – ozmuhammed 2013-02-20 15:16:06

0

如果你的新Objective-c首先查看/ ViewControllers去。即使用UIView

UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 250.0, kCCCellHeaderHeight)]; 
[subView setBackgroundColor:[UIColor redcolor]]; 
[self.view addSubview:subView]; 

addSubView财产如果你鲜为人知的UINavigationCOntroller使用pushViewController

CCFilteredVideosController *filteredController = [[CCFilteredVideosController alloc] initWithNibName:@"CCFilteredVideosController" bundle:nil]; 
[self.navigationController pushViewController:filteredController animated:YES]; 
[filteredController release]; 
+0

我改变了问题,你可以再次看看它:) – ozmuhammed 2013-02-19 19:48:20

相关问题