Forum Xamarin Xamarin.iOS

Problem with custom UITableViewCell defined on a storyboard

IvanToledoIvanToledo CLUniversity ✭✭

Hi everyone:

We have been trying unsuccesfully to use a custom UITableViewCell which is defined on a Storyboard on Xamarin.iOS

The cell is created correctly on the DequeueReusableCell call, but all the custom outlets/properties are null, so we can't modify its contents. We also tried with ViewWithTag but also returns null.

All the samples available either use the standard UITableViewCell or use a custom cell loaded from a XIB, which is unsupported on VS.

Does anyone have a clue on how to make it work? We can provide a sample project, it's just the standard UITableViewController sample with a custom cell.



  • FabioGFabioG ITBeta, University ✭✭✭

    @IvanToledo, did you use the correct Reuse Identifier when calling DequeueReusableCell, I mean the same one you defined for your prototype cell in the storyboard? Something like:

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
            var cell = tableView.DequeueReusableCell ("MyCell") as CustomCell ?? new CustomCell ();
            return cell;

    where MyCell is the Identifier and CustomCell is the Class name of your custom cell also defined the storyboard.

  • IvanToledoIvanToledo CLUniversity ✭✭

    @FabioG: Yes, the DequeueReusableCell is returning a valid cell instance of the custom class. It's just that the member outlets are null.

  • jefnazariojefnazario USMember ✭✭

    Hi @IvanToledo‌ the outlets are declared as public?

  • FabioGFabioG ITBeta, University ✭✭✭

    @IvanToledo, did you call RegisterClassForCellReuse in your UITableViewController? If so that could be the problem. I created a new project from scratch and if call RegisterClassForCellReuse in the view controller the outlets defined on the prototype cell are always null. If I don't call it everything works.

  • rnduser12skrnduser12sk USMember

    I'm having similar issues, have you found a fix yet?

  • AlessandroManfrediAlessandroManfredi ITMember
    edited November 2014

    Same problem here, no docs for this..

    After many hours i removed RegisterClassForCell and now the label is not null, still not visibile but at least i don't have binding errors.. very annoying..

  • BillDwyerBillDwyer USMember

    Thanks @FabioG ! Your solution worked for me.

    A little more context from my situation:

    I was using regular storyboard segues between my FirstViewController to call my SecondViewController. The outlets for my custom prototype cell were being populated with control references just fine. When I had to switch my setup to programatically push the SecondViewController onto the NavigationController of my FirstViewController, the outlets start having null references.

    TLDR: RegisterClassForCellReuse seems to break outlets when the ViewController is being pushed programatically.

  • ShaneNeuvilleShaneNeuville USUniversity ✭✭

    Had this same issue and from what I can tell calling "RegisterClassForCellReuse" isn't needed when the Cells are prototyped on the Storyboard because they are just "auto" registered...

    From the Xamarin docs on UITableView in designer
    They don't register the prototyped tablecells..

    The behavior is definitely confusing though because I ran into the same issue as BillDwyer did..... It was all working fine then I just changed something small about the way I was navigating and it all crapped out on me and then removing the REgisterForClass fixed it all up..

    If you call "RegisterClass" against something that's already been registered this happens

    "If you previously registered a class or nib file with the same reuse identifier, the class you specify in the cellClass parameter replaces the old entry. You may specify nil for cellClass if you want to unregister the class from the specified reuse identifier."

    So my guess is that it's some order of operations with that is causing it in some scenarios to wire up where as in others it doesn't

Sign In or Register to comment.