zoukankan      html  css  js  c++  java
  • 第三章 点击单元格

    本项目是《beginning iOS8 programming with swift》中的项目学习笔记==》全部笔记目录

    ------------------------------------------------------------------------------------------------------------------

    实现点击cell弹出alertController

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let alert = UIAlertController(title: nil, message: "What do you want to do?", preferredStyle: .ActionSheet)
        
        // 取消项
        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
       
        // 打电话项
        let callAction = UIAlertAction(title: "Call " + "123-000-(indexPath.row)", style: .Default) { (action) -> Void in
            let alertMessage = UIAlertController(title: "Service unavailable", message: "Sorry, the call feature is unavailable yet.", preferredStyle: .Alert)
           
            let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
            alertMessage.addAction(okAction)
            self.presentViewController(alertMessage, animated: true, completion: nil)
        }
       
        // 是否来过
        let isVisitedAction = UIAlertAction(title: "I've been here", style: .Default) { (action) -> Void in
            let cell = tableView.cellForRowAtIndexPath(indexPath)
            cell?.accessoryType = .Checkmark
        }
       
       
        alert.addAction(cancelAction)
        alert.addAction(callAction)
        alert.addAction(isVisitedAction)
       
        self.presentViewController(alert, animated: true, completion: nil)
    }

    效果图:

    问题及提高:

    1. 现在check了一个cell后,滚动TableView,由于单元格复用,Check会乱掉。提示:使用一个[Bool]数组成员变量记录是否需要check,可以解决。

    2. 使用心形图标替换checkmark。 提示:iconImageView.hidden = false 

  • 相关阅读:
    【光学相机】关于网络通信的方法及函数
    InvokeRequired与Invoke
    线程基本概念
    线程同步与线程异步
    AutoResetEvent和ManualResetEvent
    C#图像亮度调式与伪彩色图的处理
    Github文件高速下载方法
    JDK11以上版本没有JRE的解决方法
    mysql 随机函数生成某个范围内的整数
    mysql主键id重置
  • 原文地址:https://www.cnblogs.com/tangzhengyue/p/4303495.html
Copyright © 2011-2022 走看看