Using a Subclass for the Prototype Cell

I’m trying to create a tableview that has different cells, depending on what else is happening, so as I couldn’t find a way to hide ones I don’t need with a static table view, I thought I’d use the dynamic type. I’ve added a subclass for the first cell, but can’t seem to get the referencing outlet to connect.

I’m doing something similar to the section “Using a Subclass for the Prototype Cell” in http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1 but when I try in Xcode to set the class, it doesn’t see my custom class and even if I type the right name, I still can’t see the label’s references when I try to connect the referencing outlet, so any idea what I might be missing?

Did you decorate the class derived from UITableViewCell with the IBObject attribute ?

 [IBObject]
  PlayerCell = public class(UITableViewCell)

Thanks John that put me on the right path. I’d created it in a new file for the subclass, which was the problem. When I added the [IBObject] and moved it into the same files as the view controller, it can see it now.

You shouldn’t need to move the class into the same file. It should just work with the attribute.

I’m obviously missing something still. I created a sample, which is the standard master/detail template but I’ve changed the prototype cell to be a custom cell, with (for the sake of an example) a UITextfield instead of the normal text.

I’ve created a class called myCell for it and hooked things up in IB, but when I try to reference it in cellForRowAtIndexPath, it doesn’t work.

If anyone can look at this and see what I’m missing, I’ll be eternally grateful !
UniversalApp2.zip (134.5 KB)

The reuse identifier was wrong, I changed it to myCell

i.e PlayerCell in the picture, for you should be myCell.

http://cdn5.raywenderlich.com/wp-content/uploads/2012/11/Prototype-cell.png

And then the following works

method MasterViewController.tableView(tableView: UITableView) cellForRowAtIndexPath(indexPath: NSIndexPath): UITableViewCell;
begin
  var CellIdentifier := "myCell";
  var someCell := myCell(tableView.dequeueReusableCellWithIdentifier(CellIdentifier));

  //if not assigned(result) then
  //  result := new myCell withStyle(UITableViewCellStyle.UITableViewCellStyleDefault) reuseIdentifier(CellIdentifier);

  var lObject := fObjects[indexPath.row];
  someCell.myField:text:=lObject.description;
  //result.textLabel.text := lObject.description;
  
  exit someCell;
end;
1 Like

Odd, as I did change the identifier but obviously didn’t save it (I did the same thing again this morning when I saw your reply!)

that is the bit I was missing, and has set me on the right path. I also have moved the cell classes into a separate file and that works too.

Many thanks for your time looking at that for me John, much appreciated.