简体   繁体   中英

reload json data to UITableView

I'm a bit confused. I have 2 classes, an app delegate and a view controller. In my app delegate I get some data via this method:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];

NSDictionary *results = [responseString JSONValue];

NSArray *allTweets = [results objectForKey:@"results"];

[viewController setTweets:allTweets];
[window addSubview:viewController.view];
[window makeKeyAndVisible];

}

and in my view controller I have a button that should reload the data...I've tried a few things such as

Twitter_SearchAppDelegate *appDelegate= (Twitter_SearchAppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate connectionDidFinishLoading];

but none worked...am I going about this in the wrong way? I just want to be able to call the method that loads the data in the first place from the app delegate to the view controller. Any help is appreciated!

Yes, you are going in the wrong direction.

You are trying to call the NSURLConnection delegate method your self (wrong). If you want to simply reload the JSON data, you should call in your App Delegates method that initiates the download request to force in the data reload!

first of all , if i'm not wrong , connectionDidFinishLoading is a delegate method which is triggered when you start the connection process. have you test that your application enters connectionDidFinishLoading ?

in addition when you evaluate your array/dictionary as source to your tableview , did you call again ["your-table-view-name" reloadData] ?

hope this helps..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM