Pergunta

Eu estou no xCode 4.2 usando o ARCO e o Storyboard (o iOS 5).Suponho que para colocar os Tweets para o meu TableViewController.Como eu coloquei a minha NSURLConnection, tudo vai bem e eu tenho a resposta já está no twitter(NSArray) o delegado.O problema é que não preencher o modo de exibição de tabela.Eu estou usando SBJson para os dados recebidos.Eu estou faltando alguma coisa?

AppDelegate.m

#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}&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

Este é o delegado métodos no meu modo de exibição de tabela controlador.

- (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;
}

Eu realmente preciso de alguns conselhos.

Foi útil?

Solução

Tabela recarregar.Nossa!Eu aprendi!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top