2014-09-03 6 views
2

Heyhey!사용자 정의 셀에서 UIButton을 누른 후 새 ViewController 표시

액션 (사용자 정의 셀에 UIButton의 tappedInside)이있는 ViewController를 보여 드리고 싶습니다. 이 경우에는 사용자 정의 셀의 UIButton에서 NavigationController (ViewController가 임베드 됨)를 제어 할 수 없습니다.

테이블 뷰의 행에있는 사용자 정의 셀의 "tappedInside"에 새 ViewController가 표시된다는 것을 어떻게 알 수 있습니까?

감사합니다. 엑스 코드 6 베타 7로

답변

2

당신은 트리거 할 수 있습니다 viewcontroller를 사용하면 스토리 보드를 사용할 수 있습니다.

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
let newVC = storyboard.instantiateViewControllerWithIdentifier("myIdentifier") as youClassController 
self.presentViewController(newVC, animated: false, completion: nil) 

희망 그 도움

+0

질문은 셀 자체를 트리거하지 않고 사용자 지정 셀 안의 버튼을 트리거하는 것에 관한 것이라고 생각했습니다. –

+0

나는 그 역시 생각했습니다. –

2

, 당신의 UITableViewControllerUITableViewCell 서브 클래스는 다음과 같이 보일 것이다 :

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { 
    // some code 
} 

새로운를 열려면 : 대리자로 셀을 클릭하면

import UIKit 

class CustomCell: UITableViewCell { 

    @IBOutlet weak var button: UIButton! 

} 

class TableViewController: UITableViewController { 

    //Set method for UIButton 
    func push(sender: AnyObject) { 
     navigationController!.pushViewController(storyboard!.instantiateViewControllerWithIdentifier("ViewController") as ViewController, animated: true) //where ViewController is the name of the UIViewController and "ViewController" the identifier you set for it in your Storyboard 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1 
    } 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 1 
    } 

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomCell 
     cell.selectionStyle = .None 

     //Set button's target 
     cell.button.addTarget(self, action: "push:", forControlEvents: .TouchUpInside) 

     return cell 
    } 

} 
+0

답해 주셔서 감사합니다! Cell.button.addTarget (self, action : Selector ("push :"), forControlEvents : .TouchUpInside) – Joe

+0

스위프트를 사용하면 더 이상 셀렉터를 추가 할 필요가 없습니다. –