Load (and display) a .XIB from the web

南笙酒味 提交于 2019-12-04 15:11:34

loadNibFile:externalNameTable:withZone: is an AppKit method, so it only works on Mac OS, not iPhone or iPad.

In SDK 3.2 you can use -[UIViewController initWithNibName:bundle:] or -[NSBundle loadNibNamed:owner:options:], depending whether or not you want the File's Owner to be a UIViewController. While you're right that you can't download a .xib and install it into your main bundle's resources, you can probably download a bundle, save it into your Documents directory, pass it to +[NSBundle bundleWithPath:], and then extract a .xib from it using initWithNibName:bundle: or loadNibNamed:owner:options.

I haven't tried this, but is seems like it should work. I'll be curious to know if it does.

I'll also be very interested to know if Apple accepts this app. It seems like this would put section 3.2.2 of the iPhone SDK Agreement to the test.

You will not be able to do this with a plain .xib file, because those need to be compiled into a binary format for use within an actual application.

If you do compile the .xib files down into a proper iPhone .nib file, you might be able to place those within an external bundle and download that bundle to the application's Documents directory. You could then create an NSBundle instance using +bundleWithPath: or the like, and pass the Nib name and bundle into a UIViewController's –initWithNibName:bundle:.

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