0

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.

user1320885
  • 135
  • 1
  • 15
  • I agree with @RBI's suspicions that the problem rests in pagetwoViewController, not the tableview. If we can see the code that creates that controller and transitions to it, we can diagnose what's going on. But as an academic matter (and completely unrelated to your question), I see your IBOutlets are strong. They generally should be weak. See the [Managing the Lifetimes of Objects from Nib Files](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i-CH4-SW6) section of the Resource Programming Guide. – Rob May 20 '12 at 02:37
  • Please post the table view datasource code you are using in the implementation file (.m). – LJ Wilson May 20 '12 at 03:37
  • The .m that I posted has the datasource code. – user1320885 May 20 '12 at 13:15

1 Answers1

2

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.

RBI
  • 803
  • 2
  • 14
  • 25
  • I have the tableview hooked up through IB, isn't that the same as initializing, because I can also get information to display in it the few times it dosent crash. – user1320885 May 19 '12 at 23:15
  • Oh, I must of missed the IBOutlet at first glance. In that case hooking it up through IB takes care of initialization. – RBI May 19 '12 at 23:34
  • Now that I look at it, nszombie's error msg is stating that its the pageTwoViewController that is being released, not the tableview inside. You may want to post the code that presents this viewcontroller or explain how it is being segued if using a storyboard – RBI May 19 '12 at 23:44
  • You maybe right, as of right now my app uses a scrollview. So in the viewDidLoad of the storyboard, I init this nib and add it to the scrollView, Like This: `pagetwoViewController *pageTwoViewController = [[pagetwoViewController alloc] initWithNibName:@"pageTwoView" bundle:nil]; [scrollViewGlobal addSubview:pageTwoViewController.view]; CGRect frame = pageTwoViewController.view.frame; frame.origin.x = 1024; pageTwoViewController.view.frame = frame; self.scrollViewGlobal.contentSize = CGSizeMake(1024 * 2, 768); ` – user1320885 May 20 '12 at 13:20
  • Do you think that the original storyboard is releasing pagetwoviewcontroller? Is there any changes that i can make to the above code?? – user1320885 May 20 '12 at 16:29
  • 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 releases it on the next pool drain because it is declared locally in the viewDidLoad function of the storyBoard – RBI May 20 '12 at 17:08
  • 1
    ARC doesn't release anything, especially not on the next pool drain. More precisely, `pageTwoViewController` is being released at the end of `viewDidLoad` by the `release` that ARC adds in. There certainly won't be any autorelease pool interaction here. Note the difference in wording :-). – mattjgalloway May 20 '12 at 17:30
  • Thanks for the clarification mattgalloway. Answer has been edited. – RBI May 20 '12 at 17:53
  • I have another problem, Until now I have been returning 25 for the number of rows, but now it crashes because there are less than 25 objects in the array, so I did `[timeLineData Count]` for the numberofrows, but the count returns 0. Any Ideas?? – user1320885 May 20 '12 at 19:33