CellTableView With Twitter API won't Display Data


#1

Hello guys, I’m currently doing a practice for twitter API. Currently, i had a problem to populate a search hashtag results to tableview cellForRowAtIndexPath method. Below is my code.

My Header Code :

@interface TableViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate> @property (nonatomic,strong) NSArray *array; @end

My Implementation Code :


#import "TableViewController.h"
#import <Social/Social.h>
#import <Accounts/Accounts.h>

@interface TableViewController ()



@end

@implementation TableViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self getDataFromTwitter];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    // Configure the cell...
    NSDictionary *dataDictionary = [self.array objectAtIndex:indexPath.row];

//    NSLog(@"data result: %@", self.array);
    cell.textLabel.text = dataDictionary[@"text"];
    
    return cell;
}

- (void)getDataFromTwitter {

    // 1. set an URL
    NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/search/tweets.json"];

    // 2. set NSMutableArray For Parameter
    NSMutableDictionary *parameter = [[NSMutableDictionary alloc] init];
    [parameter setObject:@"%23MH370" forKey:@"q"];
    [parameter setObject:@"10" forKey:@"text"];
    [parameter setObject:@"popular" forKey:@"result_type"];
    
    //3. set ACAccountStore & ACAccountType
    
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    
    [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
        
        if (granted == YES) {
            NSArray *accountArray = [accountStore accountsWithAccountType:accountType];
            
            if ([accountArray count] > 0) {
                
                ACAccount *twitterAccount = [accountArray lastObject];
                
                // guna slrequest to get data from twitter
                
                SLRequest *getRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:parameter];
                
                
                // set twitter account
                [getRequest setAccount:twitterAccount];
                
                [getRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                   
                    NSString *output = [NSString stringWithFormat:@"HTTP response status : %i", [urlResponse statusCode]];
                    NSLog(@"Output : %@", output);
                    self.array = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
                  
                    if (self.array.count != 0) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                          [self.tableView reloadData];
                           NSLog(@"search result: %@", self.array);
                         });
                    }
                  
                }];
                
            }
        }
        
    }];
    
}

@end


I got a problem now when i always got a crash when i’m running the app and here is result from my console.

2014-03-12 19:57:11.990 twitterSearch[3069:a0b] -[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0xa45fd00
2014-03-12 19:57:11.992 twitterSearch[3069:a0b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0xa45fd00’

What I’m Doing wrong ?