2012-03-02 70 views
0

我通过presentModalViewController通过那里的意见做了一个应用程序。ios5 presentmodalviewcontroller多视图

第一视图是ViewController.m

#import "secondview.h" 
- (IBAction)pushme:(id)sender {  
    secondview *second = [[secondview alloc] initWithNibName:nil bundle:nil];  
    [self presentModalViewController:second animated:YES];} 

第二视图是secondview.m

#import "thirdview.h" 
- (IBAction)dismiss:(id)sender {  
    [self dismissModalViewControllerAnimated:YES];} 
-(IBAction)gohead:(id)sender{  
    thirdview *third = [[thirdview alloc] initWithNibName:nil bundle:nil];  
    [self presentModalViewController:third animated:YES];} 

第三视图thirdview.m

- (IBAction)backtomain:(id)sender {  
    [self dismissModalViewControllerAnimated:YES];} 

我的问题是当我在第三个视图中单击按钮(backtomain)时,我想返回第一个视图,而不是第二个视图。所以我如何组织backtomain功能?

谢谢〜

回答

0

您可以使用以下步骤。

  1. 在第二个存储第三个视图控制器的引用。

    @property(nonatomic,strong)secondview * modalV; (IBAction)pushme:(id)发送者 secondview * second = [[secondview alloc] initWithNibName:nil bundle:nil];(IBAction)pushme:(id)发件人 self.modalV = second; [第二版]; [self presentModalViewController:modalV animated:YES]; }

2.设置了在第三视图控制器的协议时按“backToMain”在第二视图控制器发送消息

然后,处理该消息

- (void) backToMain 
{ 
    if(self.modalV) 
    { 
     [modalV dismissModal]; // define this in third 
     [modalV release]; 
    } 

    [self dismissModalViewControllerAnimated:YES]; // it will dismiss second 
} 

第三个

- (void) dismissModal 
{ 
    [self dismissModalViewControllerAnimated:YES] 
} 
+0

嗨,我是一个初学者,所以我不能很好地理解你的代码,这里是我的文件:http://www.tempfiles.net/download/201203/232758/delay-actions.html,你可以检查它吗? – 2012-03-02 20:25:50

相关问题