Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 5 Application Development
|
BOOK: Beginning iOS 5 Application Development
This is the forum to discuss the Wrox book Beginning iOS 5 Application Development by Wei-Meng Lee; ISBN: 978-1-1181-4425-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 5 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2012, 01:23 PM
Registered User
 
Join Date: Jun 2012
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Exclamation Chapter 8 TableView cell disappearance and BAD ACCESS ERROR

I modified the Chapter 8 TableView Coding and my program works but I got errors & cell disappearance when scrolling please help to solve the error

error @ NSDictionary *tweet = [tweets objectAtIndex:indexPath.row]; BAD ACCESS


Code:
#import "TableViewViewController.h"

@interface TableViewViewController ()

@end

@implementation TableViewViewController

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"tweets array count : %d", tweets.count);
    //return tweets.count;
    return 11; //default returns 20 but only shows 10 indexpath.Row so 11
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TweetCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSLog(@"ROW : %d", indexPath.row);

    NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
    NSString *text = [tweet objectForKey:@"text"];
    NSString *name = [[tweet objectForKey:@"user"] objectForKey:@"name"];

    cell.textLabel.text = text;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name];
    return cell;
}

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

- (void)fetchTweets
{

    NSString *twitterURL = [NSString stringWithFormat:@"https://api.twitter.com/1/statuses/public_timeline.json"];    
    NSURL *fullURL = [NSURL URLWithString:twitterURL];

    NSError *error = nil;
    NSData *dataURL = [NSData dataWithContentsOfURL:fullURL options:0 error:&error];

    tweets  = [NSJSONSerialization JSONObjectWithData:dataURL
                                                      options:kNilOptions
                                                        error:&error];    
}
 
Old June 28th, 2012, 08:39 AM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

It will be helpful to see a little more of the program.
Send the nonworking program to
ipadhelper@me.com

and I should be able to sort it out for you.

Bob
The Following User Says Thank You to thepianoguy For This Useful Post:
jtown (June 28th, 2012)
 
Old June 28th, 2012, 11:27 AM
Registered User
 
Join Date: Jun 2012
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by thepianoguy
One difference between your approach and the tutorial you linked to is their use of ARC, and your not using it. If you add a retain in your fetch method the crash is resolved
- (void)fetchTweets
{

NSString *twitterURL = [NSString stringWithFormat:@"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=faraqsa&include_rts =1&count=10"];
NSURL *fullURL = [NSURL URLWithString:twitterURL];

NSError *error = nil;
NSData *dataURL = [NSData dataWithContentsOfURL:fullURL options:0 error:&error];

tweets = [[NSJSONSerialization JSONObjectWithData:dataURL
options:kNilOptions
error:&error] retain];
// tweets = [NSJSONSerialization JSONObjectWithData:dataURL
// options:kNilOptions
// error:&error];

}
Thanks for the reply you helped me BIG Tym





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8 TableView Blows Up FrankNatoli BOOK: Beginning iOS 4 Application Development 3 July 26th, 2012 11:19 AM
Question about chapter 7 tableview dave1964 BOOK: Beginning iPad Application Development 4 February 21st, 2011 02:57 PM
Author's code for chapter 8, TableView has issues rcutshaw BOOK: Beginning iOS 4 Application Development 1 January 15th, 2011 05:45 PM
cursor disappearance problem nasirmunir Javascript How-To 7 July 3rd, 2008 03:49 PM
Bad SQL in Try It Out in chapter 3 punch BOOK: Beginning SQL 1 August 18th, 2006 06:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.