开发者

UITableView creation

So in my view controller I am trying to add a table view to my view. I've created a property for it, and in my viewDidLoad method, I am initializing it like this,

//Setup the table view
se开发者_JAVA百科lf.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(160, 183, 320, 367) style:UITableViewStylePlain];
self.myTableView.dataSource = self;
self.myTableView.delegate = self;

[self.view addSubview:myTableView];

However for some reason I am getting the following error,

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MyViewController" nib but the view outlet was not set.'***

I have no IBOutlet's set or any table views in my nib file so why am I getting this error?


This error is not connected to the myTableView property. You have a nib called MyTableView in your project that is trying to be loaded but there is a problem because you did not connect the "view" outlet from the viewController (most likely the "File Owner"). If you connect that, it should be fine.

Also, you are going to leak memory unless you change your first line of code to:

self.myTableView = [[[UITableView alloc] initWithFrame:CGRectMake(160, 183, 320, 367) style:UITableViewStylePlain] autorelease];

When you allocate something, you must release it when you are done with it (the object is retained again when you set the myTableView property.)


There are several things needed to be done in IB to get the table view to load properly sounds to me that because the nib file is loading that their is no outlet set for the view in interface builder. In IB try control dragging from the file owner to the table view and when the menu pops up select view.This sets the view property of the UItableViewController to the tableview.

Not sure but something to try.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜