Is there a pre-iOS 4 replacement or workaround for UINib?

走远了吗. 提交于 2019-12-25 04:57:06

问题


My application features a tableview which contains some rather complex tableviewcells. Therefore, these cells have been designed in Interface Builder and are instanciated later as needed using UINib which allows just that - load the content from a nib and instanciate it as needed.

But UINib is only available for iOS 4.0 and above.
Before I go ahead and abandon all the 3.x users, is there a way to (easily) recreate what I'm doing using pre-iOS4 classes and methods?

Thanks alot!!


回答1:


You can load views from a nib using the following:

NSArray* nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyNibFilename" owner:self options:nil];
UITableViewCell* cell = (UITableViewCell*)[nibContents objectAtIndex:0];

Note that the index you supply to objectAtIndex: is determined by the order of the views in the nib. If the only thing in the nib is your custom table view cell, then 0 is likely the correct index.

EDIT:

It is a documented UIKit addition to NSBundle.



来源:https://stackoverflow.com/questions/3726406/is-there-a-pre-ios-4-replacement-or-workaround-for-uinib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!