Probably really a rookie question here about xcode (for the iphone)..
When I issue this command;
NSString *externalData = [NSData dataWithContentsOfURL:[NSURL URLWithString: @"http://blah.com/userli开发者_开发技巧st.txt"]];
I can see it's download from my webserver. How can I make this 1 line show in a label?
I tried; label.text = externalData; [externalData release];
But this doesn't seem to work..it seems to crash the app in the simulator. Any ideas?
It crashes because +dataWithContentsOfURL:
returns an NSData* which is not an NSString*. You want +stringWithContentsOfURL:
instead. Note though, that this will block the main thread, which may not be desirable.
Edit:
To be clear, code like this:
NSString* foo = [NSString stringWithContentsOfURL:...];
Where you replace the appropriate sections of code with your own values.
精彩评论