在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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) } } |
请发表评论