AndroidでいうListViewのようなものをiosで実装したく調べていたらTableViewにいきつきました。
行の要素にbuttonを配置しそのボタンを押すと何番目かの要素によって処理を書きたいです。
下記のように簡単にcellのテキストを変更する方法は分かったのですが自分で配置したbuttonにアクセスする方法が分かりません。
どのようにボタンにアクセスすればよいのでしょうか?よろしくお願いします。
import UIKit class MemoTableViewController: UITableViewController { var memos = ["blue", "red", "pink"] override func viewDidLoad() { super.viewDidLoad() // Uncomment the following line to preserve selection between presentations // self.clearsSelectionOnViewWillAppear = false // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of rows return self.memos.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MemoTableViewCell", for: indexPath) // Configure the cell... cell.textLabel?.text = self.memos[indexPath.row] return cell } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/16 02:08
2018/07/17 04:42
2018/07/17 04:44