开发者

UITableViewController instantiation through Interface Builder

I am starting with iOS developments here and integrate Interface Builder within my projects.

I would have a question that is something I am experiencing right now, but I am not sure if in first place if I am doing it properly.

First Case

I have created all my UITableViewController inside IB and then changed the class to my custom CurrencyTableViewController. so for adding this inside my window.rootViewController at MainWindow_iPhone.xib I am just creating a variable straight away from inside the AppDelegate and calling the instance created in another .xib file. This works pretty well, but one of my concerns here is about memory management.

//Use the instance initiated by IB
CurrencyTableViewController *currencyTableViewController    = [[[NSBundle mainBundle] loadNibNamed:@"CurrencyTableView" owner:nil options:nil] objectAtIndex:0];

So the question is: by using the method above to load instances created on IB are they released automatically after that? Or do I need to declare it somewhere else?

Second Case

This second case was an alternative trying t开发者_如何转开发o think on how to release the object, hence the creation of the instance instead the use of one instance already created. But unfortunately it seems to throw an error which says that I am not attaching the view to the controller. And this made me think that UITableViewController even being a subclass of UIViewController doesn't support the initWithNibName method...at least this is not declared on the documentation.

//Fails with: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "CurrencyTableView" nib but the view outlet was not set.'*** Call stack at first throw:
CurrencyTableViewController *currencyTableViewController    = [[CurrencyTableViewController alloc] initWithNibName:@"CurrencyTableView" bundle:nil];

So, could one please confirm if it's not supported indeed and the only possible way to create an object and attach it to a nib file is if that element is UIViewController? if not, how the code bellow could work?

Thanks in advance for your support and time.


Regarding my first case:

It seems that when you create something from IB it is released automatically, no sure though.

Regarding the second case

It wasn't working because the controller was located on the nib as well so the first thing present inside a programmatically create instance of CurrencyTableViewController was another CurrencyTableViewController instead a view for that. so you can either remove the controller and just leave the tableView itself inside the nib or declare the instance as a representation of the nib element like the example on case one.

If someone have different alternatives please let me know.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜