ios - Pass arrays data from a ViewController to a TableView -
i couldn't find specific case have pass , append 2 or more arrays of string tableview located in 2nd viewcontroller. want push 2 different strings inside 2 different uilabels
i have data gets inside through uialertviewcontroller in mainviewcontroller
var name = alertcontroller.textfields?[0].text var number = alertcontroller.textfields?[1].text
then take data , every time new set of name/number append arrays of string in mainvc
var playernames = [string]() var playernumbers = [string]() self.playernames.append(name!) self.playernumbers.append(number!)
now created table view , custom cell .xib , i'd call , set custom labels this
tableview in second viewcontroller
func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { customcell.tableviewcellnumber.text = mainvc.playernumbers[indexpath.row] customcell.tableviewcellname.text = mainvc.playernames[indexpath.row] return customcell }
so every new set makes new row name + number
i tried userdefaults performforsegue doesnt work! can print arrays fine, wont show me new rows @ all.
edit: actual question
ok guess misunderstood use of nsuserdefaults... @ moment have in viewdidload of 2nd controller
if ((userdefaults.standard.array(forkey: "playernames")) != nil){ let playernames = (userdefaults.standard.array(forkey: "playernames") as? [string])! print(playernames) } }
and printing new values, want new appended value show in custom cell label.text cell.namelabel.text = value
how retrieve value everytime , store it? if try playernames, says doesnt exist..
did synchronize user defaults after inputting data? userdefaults.synchronize()
Comments
Post a Comment