ios - Adding a UIButton to an array -


i relatively new coding in swift , i'm updating app in app store. creating array contents in cell tableview made in xib file. here looks like:

`struct calldata {     let cell : int?     let hotlinename : string?     let phonenumber : string?     let callbtn : uibutton?     let iconimg : uiimage?      init(cell:int,hotlinename:string,phonenumber:string, callbtn:uibutton, iconimg:uiimage) {         self.cell = cell         self.hotlinename = hotlinename         self.phonenumber = phonenumber         self.callbtn = callbtn         self.iconimg = iconimg      } }  class _viewcontroller: uiviewcontroller, uitableviewdelegate,uitableviewdatasource {      @iboutlet weak var tableview: uitableview!      var arrayofcalldata = [calldata(             cell: 0,             hotlinename:"",             phonenumber:"",             callbtn:"",             iconimg: #imageliteral(resourcename: "smartphone")         )] 

`

i'm not sure how insert button (callbtn) array (arrayofcalldata) without providing plenty of errors. purpose of call number within string app i'm not sure how implement action button call. here example of code calling within app:

let url = nsurl(string: "tel://8004424673")! uiapplication.shared.open(url url)

i want able incorporate array (callbtn) can create multiple buttons can call different numbers.

in calldata, save phone number callbtnaction , can fetch in selector method.

public func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell{     let cellidendifier: string = "calldatacell"      let celldata = arrayofcalldata[indexpath.row]      let cell : uitableviewcell = tableview.dequeuereusablecell(withidentifier: cellidendifier, for: indexpath)     let button = uibutton.init()     button.frame = cgrect.zero //set frame here     button.settitle(celldata.callbtntext, for: uicontrolstate.normal)     button.tag = indexpath.row     button.addtarget(self, action: selector(("buttonclicked:")), for: uicontrolevents.touchupinside)      cell.addsubview(button)     return cell  }  func buttonclicked(sender:uibutton) {     let selectedrow = sender.tag     let calldata = arrayofcalldata[selectedrow]     let action = calldata.callbtnaction     print(action)  } 

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? -