0

I am trying to add a TableView inside my UITableViewCellController like this:

enter image description here

To add content to the cells i'm doing this:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if (tableView == groupPicker) {
        var cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "")

        cell.textLabel?.text = "\(groups[indexPath.row]) - \(sets[indexPath.row]) Set\(ending(sets[indexPath.row]))"

        return cell
    }

    let cell = tableView.dequeueReusableCellWithIdentifier("cell\(indexPath.section)") as UITableViewCell

    return cell
}

groupPicker is my tableview inside the cell

I get this error:

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

on this line:

let cell = super.tableView.cellForRowAtIndexPath(indexPath)

Is there another way to do this, or am I doing something from?

(All my cells are static, I need the table view inside the cell to be dynamic)

Thanks in advance

UPDATED CODE:

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        if (indexPath.section == 0) {
            var cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "")
            cell.textLabel!.text = "Text"

            return cell
        }
        return tableView.dequeueReusableCellWithIdentifier("cell\(indexPath.section)") as UITableViewCell!
    }

I get this: (lldb) Nothing else

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30

2 Answers2

0

Firstly, you don't need to allocate the cell. All you need is to dequeue cells from your tableView. Secondly, pass an empty string instead of nil in your cell identifier. Finally and it's recommendation, separate the implementation of your cells in two different cell types. The one that contains the tableView should conform on your TableView delegate and dataSource methods first.

Edit:

You can limit the editing in your tableView based on a specific section using this delegate method

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
       editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
Ashraf Tawfeeq
  • 3,036
  • 1
  • 20
  • 34
0

Does this maybe help?

ios swift: How to have one static cell in a dynamic tableview?

I also think you need a unique identifier for each cell.

Community
  • 1
  • 1
user1555112
  • 1,897
  • 6
  • 24
  • 43
  • All my cells are static, i'm trying to add my tableview inside a static cell. – Lucas Fray Burchardt Mar 10 '15 at 07:26
  • as far as I know, that is not possible, you need to have it as dynamic prototype table view, adding there extra cells for the static content. If you find out another way, please let me know! – user1555112 Mar 10 '15 at 07:37