2014-12-05 4 views
10

안녕하세요, 버튼을 클릭하면 하나의보기 컨트롤러에서 다른보기 컨트롤러로 이동하기 위해 다음과 같은 목표 C 코드를 신속하게 변환하려고합니다. 어떤 도움이 많이보기 컨트롤러를 신속하게 프로그래밍 방식으로 표현하기

- (void)add:(id)sender { 
// Create the root view controller for the navigation controller 
// The new view controller configures a Cancel and Done button for the 
// navigation bar. 
    RecipeAddViewController *addController = [[RecipeAddViewController alloc] 
        init]; 

// Configure the RecipeAddViewController. In this case, it reports any 
// changes to a custom delegate object. 
    addController.delegate = self; 

// Create the navigation controller and present it. 
    UINavigationController *navigationController = [[UINavigationController alloc] 
         initWithRootViewController:addController]; 
    [self presentViewController:navigationController animated:YES completion: nil]; 
    } 

내 코드는 아래의 표시가 아니라 스토리 보드에 내 mainSectionViewController가 내장되어 있습니다, 네비게이션 컨트롤러에서 구현하는 방법을 잘되어이 애플의 프로그래밍 가이드에서 가져

을 감상 할 수있다 네비게이션 컨트롤러

func sectionBtnClicked (sender: UIButton!) { 


     let sectionController = self.storyboard?.instantiateViewControllerWithIdentifier("mainSectionsVC") as mainSectionViewController 


     let navController = UINavigationcontroler. ///not sure what actually comes here, any help would be appreciated 


     self.presentViewController(navController, animated: true, completion: nil) 


} 

답변

17

는 모달 navController을 제시 하시겠습니까?

이 예 경우,이 대답은

self.presentViewController(navController, animated: true, completion: nil) 

"자기",

class ViewController: UIViewController {  

    override func viewDidLoad() { 
     super.viewDidLoad() 

     var theButton = UIButton() 

     // Add the event to button 
     theButton.addTarget(self, action: "buttonTouchInside:", forControlEvents: .TouchUpInside) 

     self.view.addSubview(theButton) 
    } 

    func buttonTouchInside(sender:UIButton!) 
    { 
     // When the button is touched, we're going to present the view controller 

     // 1. Wrap your view controller within the navigation controller 

     let navController = UINavigationController(rootViewController: yourViewController) 

     // 2. Present the navigation controller 

     self.presentViewController(navController, animated: true, completion: nil) 
    } 

} 

navController

를 현재와 같이 넣어 것입니다 현재 뷰 컨트롤러하지만,

navigationControlle에서 viewController를 탐색하려면 r, 사용 가능

self.navigationController.pushViewController(viewControllerToPush, animated: true) 
14

나는 간단한 해결책을 만들었습니다. 여기에 ..

func actioncall() { 
    let loginPageView = self.storyboard?.instantiateViewControllerWithIdentifier("LoginPageID") as! ViewController 
    self.presentViewController(loginPageView, animated: true, completion: nil) 
} 
관련 문제