0

I am trying to populate a UITableView with some data that I have stored in an NSMutableArray (not sure if it should just be an Array?).

The table consists of a custom cell which I have designed in the Storyboard which I have given the identifier: courseCell

To try and populate the UITableView with my data in my NSMutableArray, I was using this tutorial: http://www.codingexplorer.com/getting-started-uitableview-swift/ however it gets to a point where they are populating the cells using "cellForRowAtIndexPath", but they are just using the default cell style and so do the following:

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

    let row = indexPath.row
    cell.textLabel?.text = swiftBlogs[row]

    return cell
}

But I am using a custom cell which has two labels.

I wasn't sure what to do, so I made an outlet for the labels and also the prototype cell:

@IBOutlet var coursesTableView: UITableView!
@IBOutlet weak var customCell: UITableViewCell!
@IBOutlet weak var courseNameLabel: UILabel!
@IBOutlet weak var courseCodeLabel: UILabel!

I am a little lost and not sure how I can go through the cellForRowAtIndexPath function, loading in my NSMutableArray data into the two labels. Any help would be appreciated!

NOTE: I am only new to StackOverflow to please let me know if I have not been clear enough.

1 Answer 1

1

If you are using a custom UITableViewCell, then you need to create a class for that custom cell (and connect the cell with the class in storyboard).

This tutorial explains very well how custom cells work: LINK

Note: Your problem is not with NSMutableArray, it's populating the custom cell.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thank you :) that video was very good (although it could have been more concise).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.