-1

this is different than what i've found on this website because everything i've found adds multiple cells upon a button push. I don't have a button and i don't see the functionality of adding multiple pieces of information to a single cell.

I made a custom cell for my UITableView and I believe it is working fine.

I have a subclass of UITableView and I only need one cell to be added. Each cell has 5 text fields that I need to add information to.

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("onlyCell", forIndexPath: indexPath) as! tableCardTableViewCell

    cell.field1.text = info1

    cell.field2.text = info2

    cell.field3.text = info3

    cell.field4.text = info4

    cell.field5.text = info5

    return cell
}

above is how I tried to add the information.

Below is how is how I tried to add the cell to the tableview

    myTable.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .Automatic) 
iman42
  • 1
  • 2
  • 2
    http://stackoverflow.com/questions/31870206/how-to-insert-new-cell-into-uitableview-in-swift/31870301#31870301 – Bhavin Bhadani Apr 20 '16 at 10:41
  • Have you create the cell in the storyboard? Also if you only have 1 cell then you just need to set the variable to 1 in the numberOrRowsInSection method. – Devster101 Apr 20 '16 at 10:42
  • i have a .xib file with the cell. I don't have it in the storyboard because i'm trying to create it using only the code – iman42 Apr 20 '16 at 11:11

1 Answers1

0

Try to use 2D Arrays in swift So that you can access the 5 elements of information regarding to each row by using indexPath.row every time

Then you can assign by using For Loop with index path.row as first parameter and index of for loop as second parameter respectively to the 2Dimensional array

I hope it works I am very new to Swift, so i am not able to explain with complete code in swift

Some code

var array2D = Array<Array<String>>()


[array2D .count] //returns the number of arrays present inside *array2D*

thank you