码迷,mamicode.com
首页 > 其他好文 > 详细

第三章 点击单元格

时间:2015-02-27 16:39:15      阅读:116      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!