iOS 7 UIActionsheet & UIAlertView demo example

ImageImageImage

Advertisements

JSON Tweeter APi using NSJSONSerialization

ViewController.h

#import <UIKit/UIKit.h>
#import “DetailViewController.h”
@interface ViewController : UIViewController<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
    IBOutlet UILabel *resultLabel;
    
    IBOutlet UITableView *table;
    NSMutableArray *myArray;
    NSDictionary *twit;
}
@end

ViewController.m

#import “ViewController.h”
#import “DetailViewController.h”
@interface ViewController ()

@end

@implementation ViewController

– (void)viewDidLoad
{
    [super viewDidLoad];
   
    //scroll.contentSize=CGSizeMake(300, 500);
    NSURLRequest *req=[NSURLRequest requestWithURL:[NSURL URLWithString:@”http://api.twitter.com/1/statuses/user_timeline.json?screen_name=vaibhavlimbani”%5D%5D;
    
    //perform request and and get JSON as a NSData obj
    
    NSData *respone=[NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
    
    NSError *jsonParsingErr=nil;
    NSArray *publicTimeline=[NSJSONSerialization JSONObjectWithData:respone options:0 error:&jsonParsingErr];
    myArray=[[NSMutableArray alloc]initWithArray:publicTimeline];
    
    
    
    for (int i =0; i<[publicTimeline count]; i++)
    {
        twit=[publicTimeline objectAtIndex:i];
        NSLog(@”Statses: %@”,[twit objectForKey:@”text”]);
        //resultLabel.text=[twit objectForKey:@”text”];
    }
    
}
    
    
    
    
    
    

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return [myArray count];
}

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
    return 1;
}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *CellIdentifier = @”Cell”;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellSelectionStyleBlue reuseIdentifier:CellIdentifier] ;
        twit=[myArray objectAtIndex:indexPath.row];

        
        cell.textLabel.text=[twit objectForKey:@”text”];
            }
    return cell;
    
}

– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    DetailViewController *detail=[[DetailViewController alloc]initWithNibName:@”DetailViewController” bundle:nil];
    
    [self presentViewController:detail animated:YES completion:nil];
    
    detail.resultLabel2.text=[[myArray objectAtIndex:indexPath.row]objectForKey:@”text”];
    NSLog(@”%@”,[[myArray objectAtIndex:indexPath.row]objectForKey:@”text”]);
    
}
Image