开发者

How should I get this Objective-C object into a local file?

I've got an iPhone app that loads a bunch of TableViews开发者_JAVA技巧. The first time a user loads the app it downloads .json from a remote server, parses that into a NSDictionary and saves it locally on the device as a .plist.

Unfortunately, I can't figure out how to do a reloadTable on the MainWindow.xib after the data loads, so it sits blank until you exit and re-enter the application. I could either spend many hours trying to figure out how to reload the TableView or just pre-load the app with the .plist file. Presumably I just drop the file into the resource folder or something in XCode and that seems like the simpler option.

My problem is that since the data is stored in the .plist I can't just load the .json file I use on the server. What's the best way to create this .plist object in a local file? I wish I could just, you know, email it to myself or pull it from the device simulator or something, but that would be way to easy.


Yes, if you put a .plist file in the Resources folder in Xcode it will get built into the application. You find the path to it with something like:

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"];

You should in fact be able to grab a copy of the .plist file your app is creating from the simulator filesystem. Look inside:

~/Library/Application Support/iPhone Simulator/User/Applications/XXXXX/Documents

(where XXXXX is a really long random hex string).


You could use notifications to send a message from the code responsible for downloading and caching the json data to the table view:

// add observer to table view
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableView) name:@"jsonDownloaded" object:nil];

// send notification from json downloader
[[NSNotificationCenter defaultCenter] postNotificationName:@"jsonDownloaded" object:self];

Alternatively, if the table view owns the json-downloading code, consider using delegates.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜