Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnection and SBJSon in AppDelegate
    primarykey
    data
    text
    <p>I'm in xCode 4.2 using ARC and Storyboard (iOS 5). I suppose to put Tweets to my TableViewController. As I placed my NSURLConnection, everything goes fine and I have the response already in tweets(NSArray) in the delegate. The problem is it doesn't populate the table view. I am using SBJson for the received data. Am I missing something?</p> <p>AppDelegate.m</p> <pre><code>#import "AppDelegate.h" #import "TwitterViewController.h" #import "SBJson.h" @implementation AppDelegate @synthesize window = _window; @synthesize receivedData; @synthesize tableViewController; @synthesize tweets; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { tweets = [NSMutableArray array]; NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://search.twitter.com/search.json?q={username}&amp;rpp=5"]]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; if (theConnection) { receivedData = [NSMutableData data]; } return YES; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [receivedData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]); NSString *responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; NSDictionary *results = [responseString JSONValue]; NSArray *allTweets = [results objectForKey:@"results"]; [tableViewController setTweets:allTweets]; } @end </code></pre> <p>This is the delegate methods in my table view controller.</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [tweets count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"twitter"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSDictionary *aTweet = [tweets objectAtIndex:[indexPath row]]; NSString *textFrom = [aTweet objectForKey:@"text"]; cell.textLabel.text = textFrom; return cell; } </code></pre> <p>I really need some advice.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload