uitableview - How to add current time to label in table view cell swift 3 -


i have add button takes new view text inputs add info. once hit add button takes tableview , adds inputs labels. having trouble making current time pull datestamp label have made. can help?

main controller

 var datestamp = date()  var clientname = [""]  var projecdescript = [""]  // custom cell make input fields custom class customcell: uitableviewcell {     //make outlets here, connect outlets cell in storyboard      @iboutlet var clientnamelabel: uilabel!     @iboutlet var descriptionlabel: uilabel!     @iboutlet var datestamp: uilabel!  }  class viewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource {      @iboutlet var clienttablelist: uitableview!      func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {         return (clientname.count)         return (projecdescript.count)     }      // new items added inputs     func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell     {         let cell = tableview.dequeuereusablecell(withidentifier: "clientcell", for: indexpath) as! customcell          // adds clients name         let companyname = clientname[indexpath.row]         cell.clientnamelabel?.text = companyname          // adds clients description         let descriptionname = projecdescript[indexpath.row]         cell.descriptionlabel?.text = descriptionname            return cell     }      func tableview(_ tableview: uitableview, caneditrowat indexpath: indexpath) -> bool {         return true     }      override func viewdidappear(_ animated: bool) {         clienttablelist.reloaddata()     } 

second controller

import uikit  class addinvoice: uiviewcontroller {      @iboutlet var clientnameinput: uitextfield!     @iboutlet var descriptionnameinput: uitextview!        @ibaction func addinvoice(_ sender: any) {          if clientnameinput.text != "" && descriptionnameinput.text != ""          {             clientname.append(clientnameinput.text!)             //clientinput.text = ""              projecdescript.append(descriptionnameinput.text!)             //descriptionfieldinput.text = ""               _ = navigationcontroller?.popviewcontroller(animated: true)         }       } } 

 let timestamp = "\(dateformatter.localizedstring(from: date(), datestyle: .long, timestyle: .long))" 

if want convert format of today

just pass date function , return string saying 3 weeks ago

 func relativepast(for date : date) -> string {  let units = set<calendar.component>([.year, .month, .day, .hour, .minute, .second, .weekofyear]) let components = calendar.current.datecomponents(units, from: date, to: date())  if components.year! > 0 {     return "\(components.year!) " + (components.year! > 1 ? "years ago" : "year ago")  } else if components.month! > 0 {     return "\(components.month!) " + (components.month! > 1 ? "months ago" : "month ago")  } else if components.weekofyear! > 0 {     return "\(components.weekofyear!) " + (components.weekofyear! > 1 ? "weeks ago" : "week ago")  } else if (components.day! > 0) {     return (components.day! > 1 ? "\(components.day!) days ago" : "yesterday")  } else if components.hour! > 0 {     return "\(components.hour!) " + (components.hour! > 1 ? "hours ago" : "hour ago")  } else if components.minute! > 0 {     return "\(components.minute!) " + (components.minute! > 1 ? "minutes ago" : "minute ago")  } else {     return "\(components.second!) " + (components.second! > 1 ? "seconds ago" : "second ago") } 

}


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -