EXC_BAD_ACCESS at UITableView on IOS

Posted by Suprie on Stack Overflow See other posts from Stack Overflow or by Suprie
Published on 2010-12-21T14:19:16Z Indexed on 2010/12/21 14:54 UTC
Read the original article Hit count: 267

Filed under:
|
|

Hi all,

When scrolling through table, my application crash and console said it was EXC_BAD_ACCESS. I've look everywhere, and people suggest me to use NSZombieEnabled on my executables environment variables. I've set NSZombieEnabled, NSDebugEnabled, MallocStackLogging and MallocStackLoggingNoCompact to YES on my executables.

But apparently i still can't figure out which part of my program that cause EXC_BAD_ACCESS. This is what my console said

[Session started at 2010-12-21 21:11:21 +0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1510) (Wed Sep 22 02:45:02 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 9335.
TwitterSearch(9335) malloc: recording malloc stacks to disk using standard recorder
TwitterSearch(9335) malloc: process 9300 no longer exists, stack logs deleted from   /tmp/stack-logs.9300.TwitterSearch.suirlR.index
TwitterSearch(9335) malloc: stack logs being written into /tmp/stack- logs.9335.TwitterSearch.tQJAXk.index
2010-12-21 21:11:25.446 TwitterSearch[9335:207] View Did Load
Program received signal:  “EXC_BAD_ACCESS”.

And this is when i tried to type backtrace on gdb :

Program received signal:  “EXC_BAD_ACCESS”.
(gdb) backtrace
#0  0x00f20a67 in objc_msgSend ()   
#1  0x0565cd80 in ?? ()
#2  0x0033b7fa in -[UITableView(UITableViewInternal)  _createPreparedCellForGlobalRow:withIndexPath:] ()
#3  0x0033177f in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] ()
#4  0x00346450 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] ()
#5  0x0033e538 in -[UITableView layoutSubviews] ()
#6  0x01ffc451 in -[CALayer layoutSublayers] ()
#7  0x01ffc17c in CALayerLayoutIfNeeded ()
#8  0x01ff537c in CA::Context::commit_transaction ()
#9  0x01ff50d0 in CA::Transaction::commit ()
#10 0x020257d5 in CA::Transaction::observer_callback ()
#11 0x00d9ffbb in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#12 0x00d350e7 in __CFRunLoopDoObservers ()
#13 0x00cfdbd7 in __CFRunLoopRun ()
#14 0x00cfd240 in CFRunLoopRunSpecific ()
#15 0x00cfd161 in CFRunLoopRunInMode ()
#16 0x01a73268 in GSEventRunModal ()
#17 0x01a7332d in GSEventRun ()
#18 0x002d642e in UIApplicationMain ()
#19 0x00001d4e in main (argc=1, argv=0xbfffee34) at /Users/suprie/Documents/Projects/Self/cocoa/TwitterSearch/main.m:14

I really appreciate for any clue to help me debug my application.

EDIT this is the Header file of table

#import <UIKit/UIKit.h>


@interface TwitterTableViewController : UITableViewController {

    NSMutableArray *twitters;

 }

@property(nonatomic,retain) NSMutableArray *twitters;

@end

and the implementation file

#import "TwitterTableViewController.h"

@implementation TwitterTableViewController

@synthesize twitters;

#pragma mark -
#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 [twitters count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 90.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    const NSInteger TAG_IMAGE_VIEW = 1001;
    const NSInteger TAG_TWEET_VIEW = 1002;
    const NSInteger TAG_FROM_VIEW = 1003;

    static NSString *CellIdentifier = @"Cell";

    UIImageView *imageView;
    UILabel *tweet;
    UILabel *from;


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

        // Image
        imageView = [[[[UIImageView alloc] initWithFrame:CGRectMake(5.0f, 5.0f, 60.0f, 60.0f)] autorelease] retain];
        [cell.contentView addSubview:imageView];        
        imageView.tag = TAG_IMAGE_VIEW;

        // Tweet
        tweet = [[[UILabel alloc] initWithFrame:CGRectMake(105.0f, 5.0f, 200.0f, 50.0f)] autorelease];
        [cell.contentView addSubview:tweet];
        tweet.tag = TAG_TWEET_VIEW;
        tweet.numberOfLines = 2;
        tweet.font = [UIFont fontWithName:@"Helvetica" size:12];
        tweet.textColor = [UIColor blackColor];
        tweet.backgroundColor = [UIColor clearColor];

        // From
        from = [[[UILabel alloc] initWithFrame:CGRectMake(105.0f, 55.0, 200.0f, 35.0f)] autorelease];
        [cell.contentView addSubview:from];
        from.tag = TAG_FROM_VIEW;
        from.numberOfLines = 1;
        from.font = [UIFont fontWithName:@"Helvetica" size:10];
        from.textColor = [UIColor blackColor];
        from.backgroundColor = [UIColor clearColor];    
    }

    // Configure the cell...
    NSMutableDictionary *twitter = [twitters objectAtIndex:(NSInteger) indexPath.row];
    // cell.text = [twitter objectForKey:@"text"];

    tweet.text = (NSString *) [twitter objectForKey:@"text"];
    tweet.hidden = NO;

    from.text = (NSString *) [twitter objectForKey:@"from_user"];
    from.hidden = NO;

    NSString *avatar_url = (NSString *)[twitter objectForKey:@"profile_image_url"];
    NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: avatar_url]];

    imageView.image = [UIImage imageWithData: imageData];
    imageView.hidden = NO;


    return cell;
}




#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary *twitter = [twitters objectAtIndex:(NSInteger)indexPath.row];
NSLog(@"Twit ini kepilih :%@", [twitter objectForKey:@"text"]);
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
   // Releases the view if it doesn't have a superview.
   [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
}


- (void)dealloc {
    [super dealloc];
}


@end

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c