首页 > 其他 > 详细

第三章 点击单元格

时间:2015-02-27 16:36:24      阅读:235      评论:0      收藏:0      [点我收藏+]

本项目是《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 

第三章 点击单元格

原文:http://www.cnblogs.com/tangzhengyue/p/4303495.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!