I have a MonoTouch application that seems to throw an exception randomly on the device:
Jan 19 11:54:31 unknown UIKitApplication:com.mycompany.myapp[0xbab7][552]
<Notice>: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.
Name: NSInternalInconsistencyException Reason:
Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/my-guid/MyApp.app> (loaded)' with name 'MyTableCellController' Jan 19 11:54:31 unknown UIKitApplication:com.mycompany.myapp[0xbab7][552] <Notice>:
at MonoTouch.UIKit.UIViewController.get_View () [0x00000] in <filename unknown>:0 Jan 19 11:54:31 unknown UIKitApplication:com.mycompany.myapp[0xbab7][552] <Notice>:
at MyDataSource.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00000] in <filename unknown>:0 Jan 19 11:54:31 unknown UIKitApplication:com.mycompany.myapp[0xbab7][552] <Notice>:
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0 Jan 19 11:54:31 unknown UIKitApplication:com.mycompany.myapp[0xbab7][552] <Notice>:
at MyApp.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0
What I have is a UIViewController with a XIB file laying out the UI. The XIB sets up a custom UITableViewCell with other controls and outlets on it, etc.
Here is an example of the GetCell method throwing the error:
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
MyCellController controller = null;
var cell = tableView.DequeueReusableCell (CellName);
if (cell == null)
{
controller = new MyCellController();
cell = (UITableViewCell)controller.View;
cell.Tag = _count++;
_controllers[cell.Tag] = controller;
}
else
{
controller = _controllers[cell.Tag];
}
controller.LoadStuff(_myArrayOfStuff[indexPath.Row]);
return cell;
}
The error occurs on the line cell = (UITableViewCell)controller.View
, and I'm assuming the error is something to do with the XIB not being loaded yet.
I've only gotten the crash to happen randomly on the device, and only when scrolling around quickly.
I've heard that XIBs are sometimes loaded asynchronously, my constructor for my UIViewController just looks like this:
public MyTableCellController () : base ("MyTableCellController", null)
{
}
Is there something I'm doing wrong here? It might be hard to make a repro for this case.