88
99import UIKit
1010
11- class NotificationsTableViewController : UITableViewController , UISearchBarDelegate {
11+ class NotificationsTableViewController : UITableViewController , UISearchBarDelegate , UITableViewDataSource {
1212
1313 var filteredNotifications = [ NotificationData] ( )
1414
1515 func filterContentForSearchText( searchText: String ) {
1616 // Filter the array using the filter method
17- self . filteredNotifications = notifications. filter ( { ( notification: NotificationData ) -> Bool in
17+ filteredNotifications = notifications. filter ( { ( notification: NotificationData ) -> Bool in
1818 let stringMatch = notification. alert. lowercaseString. rangeOfString ( searchText. lowercaseString)
1919 return ( stringMatch != nil )
2020 } )
2121 }
2222
2323 func searchDisplayController( controller: UISearchDisplayController ! , shouldReloadTableForSearchString searchString: String ! ) -> Bool {
24- self . filterContentForSearchText ( searchString)
24+ filterContentForSearchText ( searchString)
25+ println ( " searchDisplayController: " )
2526 return true
2627 }
2728
2829 func searchDisplayController( controller: UISearchDisplayController ! , shouldReloadTableForSearchScope searchOption: Int ) -> Bool {
29- self . filterContentForSearchText ( self . searchDisplayController!. searchBar. text)
30+ filterContentForSearchText ( self . searchDisplayController!. searchBar. text)
31+ println ( " searchDisplayController " )
3032 return true
3133 }
3234
3335 override func viewDidLoad( ) {
3436 super. viewDidLoad ( )
3537 println ( " viewDidLoad " )
36-
38+
3739 let notificationCenter = NSNotificationCenter . defaultCenter ( )
3840 let mainQueue = NSOperationQueue . mainQueue ( )
3941
@@ -43,59 +45,54 @@ class NotificationsTableViewController: UITableViewController, UISearchBarDelega
4345
4446 self . tableView. estimatedRowHeight = 44.0
4547 self . tableView. rowHeight = UITableViewAutomaticDimension
46-
4748 }
4849
4950 override func didReceiveMemoryWarning( ) {
5051 super. didReceiveMemoryWarning ( )
52+ println ( " didReceiveMemoryWarning " )
5153 // Dispose of any resources that can be recreated.
5254 }
5355
5456 // MARK: - Table view data source
5557 override func numberOfSectionsInTableView( tableView: UITableView ) -> Int {
56- // #warning Potentially incomplete method implementation.
57- // Return the number of sections.
5858 return 1
5959 }
6060
61- // Fix suggested at http://www.appcoda.com/self-sizing-cells/
62- //
63- override func viewDidAppear ( animated : Bool ) {
64- tableView. reloadData ( )
65- }
66-
61+ // override func viewDidAppear(animated: Bool) {
62+ // self.tableView.estimatedRowHeight = 44.0
63+ // self.tableView.rowHeight = UITableViewAutomaticDimension
64+ // tableView.reloadData()
65+ // }
66+
6767 override func tableView( tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
68- // #warning Incomplete method implementation.
69- // Return the number of rows in the section.
7068 if tableView == self . searchDisplayController!. searchResultsTableView {
71- return self . filteredNotifications. count
69+ return filteredNotifications. count
7270 } else {
7371 return notifications. count
7472 }
7573 }
7674
7775 override func tableView( tableView: UITableView , cellForRowAtIndexPath indexPath: NSIndexPath ) -> UITableViewCell {
78-
79- // println("cellForRowAtIndexPath")
80- let cell : UITableViewCell = UITableViewCell ( style: UITableViewCellStyle . Subtitle, reuseIdentifier: " ReuseCell " )
81-
76+ println ( " cellForRowAtIndexPath " , indexPath. row)
77+
8278 var notification : NotificationData
83-
8479 if tableView == self . searchDisplayController!. searchResultsTableView {
8580 notification = filteredNotifications [ indexPath. row]
8681 } else {
8782 notification = notifications [ indexPath. row]
8883 }
8984
90- cell. layer. cornerRadius = 5.0
85+ let cell : UITableViewCell = self . tableView. dequeueReusableCellWithIdentifier ( " ReuseCell " , forIndexPath: indexPath) as UITableViewCell
86+
87+ // let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "ReuseCell")
88+
89+ cell. layer. cornerRadius = 10.0
9190 cell. layer. masksToBounds = true
9291 cell. textLabel? . numberOfLines = 0
9392 cell. detailTextLabel? . numberOfLines = 0
9493
95- let timeStamp = NSDateFormatter . localizedStringFromDate ( notification. timeStamp, dateStyle: . MediumStyle, timeStyle: . ShortStyle)
96-
9794 cell. textLabel? . text = notification. alert as String
98- cell. detailTextLabel? . text = timeStamp
95+ cell. detailTextLabel? . text = NSDateFormatter . localizedStringFromDate ( notification . timeStamp, dateStyle : . MediumStyle , timeStyle : . ShortStyle )
9996
10097 if ( indexPath. row % 2 == 0 ) {
10198 cell. backgroundColor = UIColor ( white: 0.95 , alpha: 1.0 )
@@ -105,7 +102,7 @@ class NotificationsTableViewController: UITableViewController, UISearchBarDelega
105102
106103 override func tableView( tableView: UITableView , didSelectRowAtIndexPath indexPath: NSIndexPath ) {
107104 tableView. deselectRowAtIndexPath ( indexPath, animated: true )
108- println ( " selecting row: \( indexPath. row) " )
105+ println ( " selecting row: " , indexPath. row)
109106 }
110107
111108 override func tableView( tableView: UITableView , commitEditingStyle editingStyle: UITableViewCellEditingStyle , forRowAtIndexPath indexPath: NSIndexPath )
@@ -116,6 +113,7 @@ class NotificationsTableViewController: UITableViewController, UISearchBarDelega
116113 }
117114
118115 func onContentSizeChange( notification: NSNotification ) {
116+ println ( " onContentSizeChange " )
119117 tableView. reloadData ( )
120118 }
121119
0 commit comments