Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)viewWillAppear:(BOOL)animated
- {
- [self.twitterTableView reloadData];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = [UIColor clearColor];
- self.view.alpha = 1.0;
- self.twitterTableView.delegate = self;
- [mapView.layer setCornerRadius:7.0f];
- [mapView.layer setMasksToBounds:YES];
- mapView.alpha = .7;
- [twitterFrame.layer setCornerRadius:7.0f];
- [twitterFrame.layer setMasksToBounds:YES];
- [twitterTableView.layer setCornerRadius:7.0f];
- [twitterTableView.layer setMasksToBounds:YES];
- [self getTwitterData];
- }
- -(void)getTwitterData
- {
- ACAccountStore *store = [[ACAccountStore alloc] init];
- ACAccountType *twitterAccountType =
- [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
- // Request access from the user for access to his Twitter accounts
- [store requestAccessToAccountsWithType:twitterAccountType
- withCompletionHandler:^(BOOL granted, NSError *error) {
- if (!granted) {
- // The user rejected your request
- UIAlertView *noAccountAlert = [[UIAlertView alloc] initWithTitle:@"Twitter Access" message:@"To Use The Twitter Section of This App, You Must Allow Acces to Twitter" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- [noAccountAlert show];
- }
- else {
- // Grab the available accounts
- NSArray *twitterAccounts =
- [store accountsWithAccountType:twitterAccountType];
- if ([twitterAccounts count] > 0) {
- // Use the first account for simplicity
- ACAccount *account = [twitterAccounts objectAtIndex:0];
- NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:@"25" forKey:@"count"];
- // Now make an authenticated request to our endpoint
- // The endpoint that we wish to call
- NSURL *url =
- [NSURL
- URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];
- // Build the request with our parameter
- TWRequest *request =
- [[TWRequest alloc] initWithURL:url
- parameters:params
- requestMethod:TWRequestMethodGET];
- // Attach the account object to this request
- [request setAccount:account];
- [request performRequestWithHandler:
- ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
- if (!responseData) {
- // inspect the contents of error
- NSLog(@"%@", error);
- }
- else {
- NSError *jsonError;
- NSMutableArray *timeline =
- [NSJSONSerialization
- JSONObjectWithData:responseData
- options:NSJSONReadingMutableLeaves
- error:&jsonError];
- if (timeline) {
- // at this point, we have an object that we can parse
- self.timeLineData = timeline;
- }
- else {
- NSLog(@"%@", jsonError);
- }
- }
- }];
- }
- }
- }];
- [twitterTableView setDelegate:self];
- [twitterTableView reloadData];
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 25;
- }
- -(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 88.0;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSLog(@"cell for row at twitter called");
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
- }
- NSDictionary *tweet = [self.timeLineData objectAtIndex:indexPath.row];
- // NSLog(@"Tweet at index %d is %@", [indexPath row], tweet);
- //NSLog(@"Tweet: %@", tweet);
- // NSLog(@"Text in cellforpath: %@", [tweet objectForKey:@"text"]);
- if ([tweet objectForKey:@"text"] != nil) {
- cell.textLabel.text = [tweet objectForKey:@"text"];
- cell.textLabel.numberOfLines = 4;
- NSDictionary *whoPostedTweet = [tweet objectForKey:@"user"];
- NSLog(@"Name: %@", [whoPostedTweet objectForKey:@"name"]);
- cell.detailTextLabel.text = [whoPostedTweet objectForKey:@"name"];
- // cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [whoPostedTweet objectForKey:@"profile_image_url"]]]]];
- return cell;
- } else {
- cell.textLabel.text = @"Error";
- [self getTwitterData];
- NSLog(@"nil called(else) ");
- return cell;
- }
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSLog(@"Touched Table View at Row: %i", indexPath.row);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement