できること
ボタンを押すとUIActionSheetを表示して、選んだボタンのindexとタイトルを取得するだけです。
ソース
ViewController.swift
import UIKit
class ViewController: UIViewController, UIActionSheetDelegate {
@IBAction func tapButton(sender : AnyObject) {
var sheet: UIActionSheet = UIActionSheet()
let title: String = "Please choose a plan"
sheet.title = title
sheet.delegate = self
sheet.addButtonWithTitle("Cancel")
sheet.addButtonWithTitle("A plan")
sheet.addButtonWithTitle("B plan")
sheet.addButtonWithTitle("C plan")
// キャンセルボタンのindexを指定
sheet.cancelButtonIndex = 0
// UIActionSheet表示
sheet.showInView(self.view)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func actionSheet(sheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int) {
println("index %d %@", buttonIndex, sheet.buttonTitleAtIndex(buttonIndex))
}
}