In MonoTouch, there are many examples out there where people load NIB files like this:
var customController = new MyCustomController();
NSBundle.MainBundle.LoadNib("MyCustomController", customController, null);
Based on many code samples I have seen on blog posts, people tend to do this for custom UITableViewCells which they have designed in Interface Builder.
That is all well and good – but perhaps the NIB file contains more than one custom UITableViewCell. I have found a blog post that shows a single NIB file being used that contains multiple custom table cells (in Objective-C):
http://pegolon.wordpress.com/2008/11/15/using-uitableviewcell-with-interfacebuilder/
That is doing what I want!
In that Objective-C example, it becomes clear that NSBundle.MainBundle.LoadNib actually returns something (an NSArray) and then the returned object is iterated over: each object in the NSArray is a table cell “template”.
When I try to do this in MonoTouch/C#, I am struggling to iterate over the returned NSArray. It doesn’t let me access its contents with array indexers, and it won’t let me loop over it.
How can I do it?
Ok, I have managed to get it working. The important thing is how to get objects from an
NSArray:I have also created a sample project and article about how to use custom table cells from nib files:
Custom Table Cells in MonoTouch