Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 5 Application Development
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 27th, 2012, 01:23 PM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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];    
}
Reply With Quote
  #2 (permalink)  
Old June 28th, 2012, 08:39 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
The Following User Says Thank You to thepianoguy For This Useful Post:
jtown (June 28th, 2012)
  #3 (permalink)  
Old June 28th, 2012, 11:27 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.