, 당신의 UITableViewController
및 UITableViewCell
서브 클래스는 다음과 같이 보일 것이다 :
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
}
}
질문은 셀 자체를 트리거하지 않고 사용자 지정 셀 안의 버튼을 트리거하는 것에 관한 것이라고 생각했습니다. –
나는 그 역시 생각했습니다. –