iT邦幫忙

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

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

UIAlertController 與 tableview 之互動( D day + 10 )

之前我們使用都只讓 tableview 顯示圖片和資料,今天我們讓他和使用者有點互動。
以下為處理列被選取時的方法

fun tableView(UITableView,willSelectRowAt: indexPath)
fun tableView(UITableView,didSelectRowAt: indexPath)

  1. 首先開啟 “RestaurantTableViewController.swift
  2. 鍵入
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
            
        // Create a menu of action list
        let optionMenu = UIAlertController(title: nil, message: "Hi, Cell has been select", preferredStyle: .actionSheet)

        // Add action into the list
        
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
            optionMenu.addAction(cancelAction)
            
        // Present the menu
        present(optionMenu, animated:true, completion: nil)

    }
  1. 按下 Build -> 點選 simulator 上任何一列就會出現以下結果了。
    https://ithelp.ithome.com.tw/upload/images/20171230/20107698n1eAJS9oYI.png

  2. 如果把 preferredStyle 改為 .alert 就會出現不一樣的結果

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

https://ithelp.ithome.com.tw/upload/images/20171230/20107698qFPEi9cNrp.png


上一篇
如何自訂Cell格式與內容 ( D day + 9 )
下一篇
UIAlertController 與 tableview 之互動 (二) ( D day + 11 )
系列文
挑戰 30天內送審一支APP 30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言