2011-09-27 67 views
2

請幫我解決下面提到的問題。iPad拆分視圖從另一個視圖調用/加載

我的問題是,是否有辦法從另一個視圖調用拆分視圖,比如我點擊一個按鈕後說......?

例如,如attached pic所示,當應用程序啓動時,它會顯示第一個屏幕。

當用戶點擊「單擊」按鈕時,分割視圖打開。

用戶能夠執行分割視圖的所有操作,並且當他按下主頁按鈕時,他應該被帶回第一個屏幕。

這是可能的..?我怎麼去解決它..?

我是初學者。任何幫助代碼將不勝感激..

PS:我已經嘗試使用MGSplitView和TOSplitView,但一直未能實現上述問題的解決方案。

謝謝...

回答

3

檢查foll代碼。這應該很容易幫助你解決你的問題。

//Intialise the 2 views root and detail 
    RootViewController * rootVC = [[RootViewController alloc] initWithStyle:UITableViewStylePlain]; 

    //To show the nav bar for root, add it into a UINavigationController 
    UINavigationController * rootVCNav = [[UINavigationController alloc] initWithRootViewController:rootVC]; 


    DetailViewController * detailVC = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; 

    //initialise split view 
    splitVC = [[UISplitViewController alloc] init]; 
    splitVC.viewControllers = [NSArray arrayWithObjects:rootVCNav,detailVC, nil]; 

    //Tell the split view that its delegate is the detail view. 
    splitVC.delegate = detailVC; 
    //tell root that the changes need to be shown on detail view. 
    rootVC.detailViewController = detailVC; 


    [rootVC release]; 
    [detailVC release]; 
    [rootVCNav release]; 

    //Here, we get the app delegate object of the project 
    ProjectAppDelegate * appDel = (ProjectAppDelegate*)[[UIApplication sharedApplication] delegate]; 

    //get window object of the delegate 
    UIWindow * window1 = [appDel window]; 
    //get the navigation controler of the window of app delegate. 
    mainNav = [appDel rVC]; 

    //remove the current view from the window. 
    [mainNav.view removeFromSuperview]; 

    //add the split view to the window 
    [window1 addSubview:locSplitVC.view]; 

希望這有助於你..

問候, 梅爾文

+0

謝謝梅爾文.. 這僅僅是完美.. !!! –

1

IM做這種類型的,但我沒有得到拆分視圖

  • (無效)viewDidLoad中 { [super viewDidLoad]; MainViewController * first = [[MainViewController alloc] initWithNibName:@「MainViewController」bundle:nil];

    UINavigationController * sec = [[UINavigationController alloc] initWithRootViewController:first];

    DetailViewController * detail = [[DetailViewController alloc] initWithNibName:@「DetailViewController」bundle:nil]; UINavigationController * detailv = [[UINavigationController alloc] initWithRootViewController:detail];

    UISplitViewController * split = [[UISplitViewController alloc] init];

    split.viewControllers = [NSArray arrayWithObjects:sec,detailv,nil];

    // split.delegate = detail;

    split.delegate = self;

    //首先。詳細=細節;

    appDel =(AppDelegate *)[[UIApplication sharedApplication] delegate];

    window1 = [appDel window];

    UINavigationController * mainNav = [[UINavigationController alloc] init];

    mainNav = [appDel nav]; [mainNav.view removeFromSuperview];

    [window1 addSubview:split.view];

    //在從其筆尖加載視圖後執行任何其他設置。 }

相關問題