Search code examples
iosuitableviewios5automatic-ref-countingnszombie

UITableView ARC issue


Right now I am making an app that uses a UITableView, but I have been struggling with this issue for 3 days now and I can't figure it out.

In the .h File, I subscribe to both the tableview methods. Like this:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <QuartzCore/QuartzCore.h>
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>


@interface pagetwoViewController : UIViewController <UITableViewDataSource,  UITableViewDelegate>
{

}

@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@property (strong, nonatomic) IBOutlet UIImageView *twitterFrame;
@property (strong, nonatomic) IBOutlet UITableView *twitterTableView;
@property (strong, nonatomic) NSMutableArray *timeLineData;

And my implementation can be found here:

.m file

It always crashes whenever app loads up. So I enabled NSZombies and I got the message:

[pagetwoViewController numberOfSectionsInTableView:]: message sent to deallocated instance 0x27d960

So I looked this up online, and I found that in almost all cases, this happens when the tableview gets released before numberOfSectionsInTableView. All the websites say that I should retain the tableview, but I am using ARC and I can not do that. This crash only happens sometimes. And then When it doesn't, the moment I try touch the tableview or try to scroll it, It crashes. I've looked everywhere and I simply can't find anything on this issue, And I certainly can't figure out where the tableview is being released. Any help whatsoever will be greatly appreciated.


Solution

  • Are you sure your even initializing the tableview? Your .h does not have an outlet described for the tableview which suggests it is not hooked up to anything in a storyboard/xib and your .m does not initialize the table programmatically.

    Edit: Answer #2 Try moving the pagetwoViewController declaration to the header of the storyboard... Your problem is that your only adding the view of the pageTwoViewController therefore ARC adds the release to the viewController at the end of viewDidLoad because it is declared locally.