Как определить, используется ли ячейка просмотра таблицы. В руководствах и учебниках в Интернете следуют подход добавления кнопки в ячейку ячейки ячейки - прототипа. Эта кнопка остается одинаковой для всех строк, а при нажатии - возвращает индекс строки или ячейки.Как определить, используется ли ячейка просмотра таблицы в xcode 7
Я хочу сделать это без кнопки. Как я могу позвонить
@IBAction
, когда ячейка прослушивается, а затем выполняет функцию внутри функции.
Как мне это сделать?
Я добавил следующий код, но это не печатает ничего
class MoreViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let moreOption = [
("My Profile"),
("Settings"),
("Logout")
]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.navigationController!.navigationBar.barTintColor = UIColor(red: (48/255.0), green: (187/255.0), blue: (197/255.0), alpha: 1.0);
self.navigationController!.navigationBar.tintColor = UIColor .whiteColor();
self.navigationController!.navigationBar.translucent = false;
self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor .whiteColor()]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func logout() {
print("Logout tapped");
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return moreOption.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
let (celloption) = moreOption[indexPath.row];
cell.textLabel!.text = celloption;
cell.textLabel!.textColor = UIColor(red: (74/255.0), green: (74/255.0), blue: (74/255.0), alpha: 1.0);
return cell;
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
print(cell);
}
}
вам просто нужно использовать метод didSelectRow UITableViewDelegate. – Sahil