• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ChatsViewController.swift

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

import UIKit

class ChatsViewController:UITableViewController {

  var chats:[Chat] {return account.chats}

  conenience override init() {

    self.init(style: .Plain)

    title = "Chats"

  }

 

  override func viewDidLoad() {

    super.viewDidLoad()

    let minute:NSTimeInterval = 60,hour = minute * 60, day = hour *24

    account.chats = [

      

Chat(user: User(ID: 2, firstName: "Angel", lastName: "Rao"), lastMessageText: "6 sounds good :-)", lastMessageSentDate: NSDate()),

            Chat(user: User(ID: 3, firstName: "Valentine", lastName: "Sanchez"), lastMessageText: "Haha", lastMessageSentDate: NSDate(timeIntervalSinceNow: -minute)),

            Chat(user: User(ID: 23, firstName: "Ben", lastName: "Lu"), lastMessageText: "I have no profile picture.", lastMessageSentDate: NSDate()),

            Chat(user: User(ID: 4, firstName: "Aghbalu", lastName: "Amghar"), lastMessageText: "Damn", lastMessageSentDate: NSDate(timeIntervalSinceNow: -hour*13)),

            Chat(user: User(ID: 22, firstName: "中文 日本語", lastName: "한국인"), lastMessageText: "I have no profile picture or extended ASCII initials.", lastMessageSentDate: NSDate()),

            Chat(user: User(ID: 5, firstName: "Candice", lastName: "Meunier"), lastMessageText: "I can't wait to see you! ❤️", lastMessageSentDate: NSDate(timeIntervalSinceNow: -hour*34)),

            Chat(user: User(ID: 6, firstName: "Ferdynand", lastName: "Kaźmierczak"), lastMessageText: "http://youtu.be/UZb2NOHPA2A", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*2-1)),

            Chat(user: User(ID: 7, firstName: "Lauren", lastName: "Cooper"), lastMessageText: "Thinking of you...", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*3)),

            Chat(user: User(ID: 8, firstName: "Bradley", lastName: "Simpson"), lastMessageText: "????", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*4)),

            Chat(user: User(ID: 9, firstName: "Clotilde", lastName: "Thomas"), lastMessageText: "Sounds good!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*5)),

            Chat(user: User(ID: 10, firstName: "Tania", lastName: "Caramitru"), lastMessageText: "Cool. Thanks!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*6)),

            Chat(user: User(ID: 11, firstName: "Ileana", lastName: "Mazilu"), lastMessageText: "Hey, what are you up to?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*7)),

            Chat(user: User(ID: 12, firstName: "Asja", lastName: "Zuhrić"), lastMessageText: "Drinks tonight?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*8)),

            Chat(user: User(ID: 13, firstName: "Sarah", lastName: "Lam"), lastMessageText: "Are you going to Blues on the Green tonight?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*9)),

            Chat(user: User(ID: 14, firstName: "Ishan", lastName: "Sarin"), lastMessageText: "Thanks for open sourcing Chats.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*10)),

            Chat(user: User(ID: 15, firstName: "Stella", lastName: "Vosper"), lastMessageText: "Those who dance are considered insane by those who can't hear the music.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),

            Chat(user: User(ID: 16, firstName: "Georgeta", lastName: "Mihăileanu"), lastMessageText: "Hey, what are you up to?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),

            Chat(user: User(ID: 17, firstName: "Alice", lastName: "Adams"), lastMessageText: "Hey, want to hang out tonight?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),

            Chat(user: User(ID: 18, firstName: "Gerard", lastName: "Gómez"), lastMessageText: "Haha. Hell yeah! No problem, bro!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),

            Chat(user: User(ID: 19, firstName: "Melinda", lastName: "Osváth"), lastMessageText: "I am excellent!!! I was thinking recently that you are a very inspirational person.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),

            Chat(user: User(ID: 20, firstName: "Saanvi", lastName: "Sarin"), lastMessageText: "See you soon!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),

            Chat(user: User(ID: 21, firstName: "Jade", lastName: "Roger"), lastMessageText: "????", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11))

 

    ]

    navigationItem.leftBarButtonImte = editButtonItem()

    tableView.backgroundColor = UIColor.whiteColor()

    tableView.rowHeight = chatCellHeight

    tableView.separatorInset.left = chatCellInsetLeft

    tableView.registerClass(ChatCell.self,forCellReuseIdentifier:NSStringFromClass(ChatCell))   //NSStringFromClass

  }

  override func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int {

    return chats.count

  }

 

  override func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath) {

    let cell = tableView.dequeReuseableCellWithIdentifier(NSStringFromClass(ChatCell))

    cell.configureWithCaht(account.chats[indexPath.row])

    return cell;

  }

 

  override func tableView(tableView:UITableView,commitEditingStyle editingStyle:UITableViewCellEditingStyle,forrowAtIndexPath indexPath:NSIndexPath) {

  if editingStyle = .Delete {

    account.chats.removeAtIndex(indexPath.row)

    tableView.deleteRowsAtIndexPath([indexPath],withRowAnimation:.Fade)

    if account.chats.count == 0 {

      navigationItem.leftBarButtonItem = nil

    }

  }

}

  override func tableView(tableView:UITableView, didSelectRowAtIndexPath:NSIndexPath) {

    let chat = chats[indexPath.row]

    let chatViewController = ChatViewController(chat:chat)

    navigationController?.pushViewController(chatViewController,animated:true)

  }

}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Swift开发第九篇——Any和AnyObject&typealias和泛型接口发布时间:2022-07-13
下一篇:
[Swift]LeetCode1034.边框着色|ColoringABorder发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap