iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 12
0
Software Development

挑戰 30天內送審一支APP 系列 第 12

UIAlertController 與 tableview 之互動 (二) ( D day + 11 )

昨天用了 UIAlertController 結合 tableView 建立一個互動表單,今天想要在表單內新增一個“撥打電話”的功能,但是並沒有真的要打出去,而是希望 User 點選後會跳出另一段訊息,我們應該怎麼做呢?
先來回想一下昨天怎麼建立一個提示控制器

建立選單
加入動作進入選單
呈現選單

let optionMenu = UIAlertController(title: nil, message: "Hi, Cell has been select", preferredStyle: .alert)

let 實體化名稱 = 控制器名稱 ( 標題 : __ , 顯示訊息 : __ , 呈現樣式 : __ )

這次我們新加入一個物件”callActionHandler”,並且使用 closure (閉包 )

// add Call action into option menu
            let callActionHandler = { (action:UIAlertAction!) -> Void in
                let alertMessage = UIAlertController(title:"Out of service",message:"Soooooooory, the call is not available, please try next year", preferredStyle: .alert)
                alertMessage.addAction(UIAlertAction(title:"OK",style:.default, handler: nil))
                self.present(alertMessage, animated: true, completion:nil)
                
            }
            let callAction = UIAlertAction(title:"Call"+"882-5252-\(indexPath.row)",style: .default, handler:callActionHandler)
            optionMenu.addAction(callAction)

結果 :

對照一下會比較清楚


上一篇
UIAlertController 與 tableview 之互動( D day + 10 )
下一篇
UIAlertController 與 tableview 之互動 (三)( D day + 12 )
系列文
挑戰 30天內送審一支APP 30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
陳董 Don
iT邦新手 5 級 ‧ 2017-12-31 18:52:50

讚讚讚~

我要留言

立即登入留言