Currently i have an uitableview
with a custom cell.
It contains an uilabel
and uibutton
- data source for which is fetched from two separate arrays.
The uibutton
function is to append the corresponding array with lines for the uilabel
and insert them in the uitableview
as well as add a new cell with another uibutton
below.
There is one conditional - once the question array value is nil, the answer uibutton
is shown.
The issue is - because the uibutton
name is fetched as the last value from the array, once i scroll all the button titles are being re-written to match the latest one.
Here is my code
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return numberofsections
// is always equal to zero
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return someTagsArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell
cell.lblCarName.text = someTagsArray[indexPath.row]
cell.act1.setTitle(answersdict.last, forState:UIControlState.Normal)
return cell
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
var cell:TblCell = cell as! TblCell
if let text = cell.lblCarName.text where text.isEmpty {
cell.act1.hidden = false
} else {
println("Failed")
}
}
Is there any way to store those uibutton
values or prevent the cell from being reused completely.
Some more data on my question\answer model I have a dictionary with the nested array called linesmain for questions
linesmain = ["first":["question 1", "question 2", "question 3"], "answer 1": ["question 1", "question 2", "question 3"], "answer 2": ["question 1", "question 2", "question 3"], "answer 3":["question 1", "question 2", "question 3"]]
and a similar dictionary for answers
answersmain = ["first": ["answer 1"], "answer 1": ["answer 2"], "answer 2": ["answer 3"], "answer 3":["answer 4"]]
i keep it that way because i might increase the amount of answers in the future.
Then i have two arrays for the cells to append.
One appends - the questions (someTagsArray), another one - the answers (answersdict).
On launch the "first" questions and answers are loaded, then depending on the uibutton
currentTitle in the newly appended cell.
Thank you.