0

I am trying to load different nibs into a single UITableView depending on a variable within a model. I seem to have something that looks logical and doesn't crash, however, only 1 of the xibs is being loaded and displayed.

Controller Method:

private void populateTableData()
    {
        liveTipsTableView.RegisterNibForCellReuse(UINib.FromName("LiveTipCell_", null), "LiveTipCell_");
        liveTipsTableView.RegisterNibForCellReuse(UINib.FromName("NewsCell_", null), "NewsCell_");

        setListViewSource();
        Refresh();
        AddRefreshControl();
        Add(liveTipsTableView);
        liveTipsTableView.Add(RefreshControl);
    }

TableSource Method

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        var localTip = _tips[indexPath.Row];

        if (localTip.NewsItem)
        {
            CellIdentifier = new NSString("NewsCell_");
            NewsCell_ cell = new NewsCell_();
            cell = tableView.DequeueReusableCell("NewsCell_") as NewsCell_;
            var views = NSBundle.MainBundle.LoadNib("NewsCell_", cell, null);
            cell = ObjCRuntime.Runtime.GetNSObject(views.ValueAt(0)) as NewsCell_;
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            cell.BindDataToCell(localTip);
            return cell;
        }
        else
        {
            CellIdentifier = new NSString("LiveTipCell_");
            LiveTipCell_ cell = new LiveTipCell_();
            cell = tableView.DequeueReusableCell("LiveTipCell_") as LiveTipCell_;
            var views = NSBundle.MainBundle.LoadNib("LiveTipCell_", cell, null);
            cell = ObjCRuntime.Runtime.GetNSObject(views.ValueAt(0)) as LiveTipCell_;
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            cell.BindDataToCell(localTip);
            return cell;
        }
    }

I have 2 separate Xib files and they have their own classes which work to populate the views. They all seem to getting used when debugging, it's just a case of the table view is only displaying 1 of these items.

Thanks in advance and please let me know if you need more information to see what's going on.

Phill Wiggins
  • 2,577
  • 4
  • 28
  • 33

1 Answers1

0

This is in objective C, but it shouldn't be too hard to convert.

SO Post on a different question

Community
  • 1
  • 1
JoeTomks
  • 3,243
  • 1
  • 18
  • 42
  • Thanks @Digitalsa1nt . I had a read of this but couldn't see much difference between that and what I have implemented. I'm not an iOS expert so not sure if there's something I'm overlooking here. – Phill Wiggins Mar 23 '17 at 16:54
  • hmm interesting. OK just to confirm you've set the 'identifier' for both nibs appropriately? – JoeTomks Mar 23 '17 at 17:00
  • Yes both seem to be named correctly and both have unique names. It's strange as it usually would pop up with a build error if that was the case, so I don't think it's that. It's as though one of the view is just hidden or not visible, i.e. debugging line by line shows that each line of code runs correctly and doesn't just cut out? – Phill Wiggins Mar 23 '17 at 17:05
  • It seems as though it's only keeping one reference to one nib. But that doesn't really make a lot of sense. It might be worth while, testing it with one nib then the other, just to see that both are being populated correctly and your not getting any strange issues. – JoeTomks Mar 23 '17 at 17:10
  • So I have 2 objects that are very similar, but populated into 2 separate layouts. When I load both objects into my tableview and try to load them in separate xibs, 1 of the objects loads correctly in the correct layout, the other doesn't appear at all. When I try to load both into the same layout (As the objects are similar enough to do so) only 1 uitableviewcell appears, but isn't populated and all views are missing. Very strange behaviour. – Phill Wiggins Mar 23 '17 at 17:27
  • Actually I'm incorrect, if I load both views into the same XIB for one of the XIB's, very strange reaction. If I load them into the other it works perfectly. I'll try see if I figure this out. Probably a layout/XIB issue. – Phill Wiggins Mar 23 '17 at 17:33
  • yeah I suspect your getting closer to the issue. if anything else crops up, keep us posted and we can work through it. – JoeTomks Mar 23 '17 at 17:43