Iphone 在mainviewcontroller中加载多个ViewController

Iphone 在mainviewcontroller中加载多个ViewController,iphone,Iphone,具有作为uiimageview和uitoolbar的mainviewcontroller,当按下uitoolbar上的按钮时,它会根据nstimer逐个加载多个视图控制器。我想将此mainviewcontroller作为容器,用于根据nstimer和uitoolbar逐个加载多个视图控制器,如下所示。不希望将工具栏作为子视图添加到每个视图控制器中。我该怎么做呢 - (void)viewDidLoad{ // Displays UIImageView UIImageView *myImage =

具有作为uiimageview和uitoolbar的mainviewcontroller,当按下uitoolbar上的按钮时,它会根据nstimer逐个加载多个视图控制器。我想将此mainviewcontroller作为容器,用于根据nstimer和uitoolbar逐个加载多个视图控制器,如下所示。不希望将工具栏作为子视图添加到每个视图控制器中。我该怎么做呢

- (void)viewDidLoad{
// Displays UIImageView
UIImageView *myImage = [[UIImageView alloc]
                         initWithImage:[UIImage imageNamed:@"ka1_046.png"]];
myImage.frame = CGRectMake(0, 0, 320, 460);
[self.view addSubview:myImage]; 
// create the UIToolbar at the bottom of the view controller
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 425, 320, 40)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[self.view addSubview:toolbar];

//Add Play Button
self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.playButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
self.playButton.frame = CGRectMake(0, 0, 30, 30);
[self.playButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateNormal];
[self.playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
 UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithCustomView:self.playButton];

-(void)playpauseAction:(id)sender {
if([audioPlayer isPlaying])
{
    [sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
    [audioPlayer pause];
    [self pauseTimer];
    [self pauseLayer:self.view.layer];

}else{
    [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    [audioPlayer play];
    [self resumeTimer];
    [self resumeLayer:self.view.layer];
   if(isFirstTime == YES)
    {
        self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                            target:self
                                            selector:@selector(displayviewsAction:)
                                             userInfo:nil
                                             repeats:NO];
        isFirstTime  = NO;
    }} }


  - (void)displayviewsAction:(id)sender{  
     First *first = [[First alloc] init];
     first.view.frame = CGRectMake(0, 0, 320, 480);
     CATransition *transitionAnimation = [CATransition animation];   
     [transitionAnimation setDuration:1];
     [transitionAnimation setType:kCATransitionFade];
     [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
     [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];
     [self.view addSubview:first.view];
     [self.view addSubview:toolbar];
     [first release];   
     self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];     
     }
同样,基于nstimer逐个加载其他多个视图控制器。因此,如何使这个mainviewcontroller成为容器,以基于nstimer和始终在下面具有uitoolbar的方式一个接一个地加载这些多个视图控制器


谢谢您的帮助。

如果您想留在主视图控制器中,那么根据定义,您不能推送任何其他视图控制器。你所能做的,就是创建所有其他的东西作为UIView,然后将它们作为子视图添加到你的主VC中。这意味着您的所有代码都将在同一个.m文件中,但这不应该是一个问题。

将多个EVC作为uiview添加到主vc的子视图中是令人困惑的,在主vc的子视图中处理vc之间的转换必须使用addtosubview RemoveFromSubView对不起,我不太明白您的要求。你能澄清一下吗?我添加了UIView*baseView=[[UIView alloc]initWithFrame:CGRectMake(0,0320480)];[self.view addSubview:baseView];如果我添加[baseView addSubview:first.view],则在UIImageView顶部和displayviewaction中;因此,根据playpauseAction,它在11秒后将UIImageView替换为first.view作为子视图。它给出了使用未声明的标识符baseView的消息。用presentmodal呈现ViewController,然后用这种方式消除它怎么样。或者使用导航控制器。所以你可以设法切换到视图。