アプリ開発を始めて,ついでにQiita初投稿.
TableViewのアクセサリーボタンにタグ付け成功.
1000の位はセクション,1の位はセルの行を表しています.
TestTableView.swift
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var _myTableView: UITableView!
let SECTION_NAME = ["Clip", "History"]
var _clipItemArray = ["iOS8", "iOS7", "iOS6", "iOS5", "iOS4"]
var _historyItemArray = ["5.x", "4.x", "2.x", "1.x"]
//略
// セルの内容
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) as UITableViewCell
let button = UIButton(frame: CGRectMake(0, 0, BUTTON_SIZE, BUTTON_SIZE))
button.setImage(UIImage(named: "Icon180.png"), forState: .Normal)
button.addTarget(self, action: "tmpButtonTouch:", forControlEvents: UIControlEvents.TouchUpInside)
button.tag = indexPath.section*1000+indexPath.row
cell.accessoryView = button
if indexPath.section == 0 {
cell.textLabel!.text = "\(_recordItemArray[indexPath.row])"
} else if indexPath.section == 1 {
cell.textLabel!.text = "\(_historyItemArray[indexPath.row])"
}
return cell
}
func tmpButtonTouch(sender: UIButton!) {
var button: UIButton = sender
println("button.tag: \(button.tag)")
}