0

I am receiveing this error message when launching a IBAction from an NSView.

XXXX is AccountTableCellViewController I did put it with an abstract name in case it can help other prople.

This is the structure of the components:

I have an app where I load this view: enter image description here

Using this NSView as cell enter image description here

The TableView has been binded like this:

@property (nonatomic,retain) IBOutlet NSTableView *tableView;

I display the contents as follows (I have some doubts on not linking the controller anywhere)

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    Account *account = (Account *)[self.dataSource objectAtIndex:row];

    AccountTableCellViewController *controller = [[AccountTableCellViewController alloc] initWithNibName:@"AccountTableCellViewController" bundle:nil ];
    controller.account = account;
    return [controller view] ;
}

Any idea?

Mc-
  • 3,968
  • 10
  • 38
  • 61
  • are you using ARC? also do a static analysis first which may found the bug – Bryan Chen Jan 19 '13 at 13:26
  • You have a view in your `Application` instance? That's not even possible is it; you must use an App Delegate... Perhaps you have the wrong row selected in the `Placeholders` section? – trojanfoe Jan 19 '13 at 13:28
  • @xlc0212 yes, I am using ARC. Analyse didn't gave me any info. – Mc- Jan 19 '13 at 14:46
  • @trojanfoe Yes, I have a MainApp.xib, I didn't put it on the question because I don't think it affects to the result. – Mc- Jan 19 '13 at 14:47
  • What type is "XXXX"? I ask because it's one of those that is getting freed and then re-used. You should look where you're freeing those objects and make sure they don't get re-used after they're freed. – user1118321 Jan 19 '13 at 15:38
  • XXXX is AccountTableCellViewController, I did put it that way in case it can help more people, sorry for the confusion. – Mc- Jan 19 '13 at 15:41
  • 1
    I notice that you create the controller, but you don't keep track of it. After you return its view, you never do anything with it again. I don't know ARC well enough to know what it does with that instance, but could it be deallocating it and then the view is trying to access it again later? – user1118321 Jan 19 '13 at 15:56
  • I thought the same. I created a controllers NSMutableArray property and syntethized and I stored the controller for each one of the rows (Just testing). It didn't solve the issue :S. – Mc- Jan 19 '13 at 16:02
  • 2
    Given your description, I suspect you then forgot to initialize the `NSMutableArray`. If you don't do that, then the property will be `nil` and you won't actually store the controllers. – Rob Napier Jan 19 '13 at 17:56
  • @RobNapier your comment has been key, I did add the controllers to the array, but I never initialized it... what a fool... xD Thank you! XCOde should dispatch an error in this cases. Do you think is a good practice? How should I keep clean the memory if every row adds a controller to the array? removing the array when removing the view? – Mc- Jan 19 '13 at 18:59
  • Sending a message to nil is not an error. It is a normal case. Yes, it is fine that there is an array of sub-controllers that is released when the main controller is deallocated. It is unusual to have all these sub-controllers, though that may be fine depending on the rest of the design. – Rob Napier Jan 19 '13 at 23:49

1 Answers1

1

This is a pre-ARC equivalent of your code

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    Account *account = (Account *)[self.dataSource objectAtIndex:row];

    AccountTableCellViewController *controller = [[AccountTableCellViewController alloc] initWithNibName:@"AccountTableCellViewController" bundle:nil ];
    controller.account = account;
    NSView *result = [[controller view] retain];
    [controller release]; /// !!!
    return [result autorelease];
}

Your controller is already deallocated at the moment tableView:viewForTableColumn: returns. You say in comments that you've tried to keep controllers in array but it doesn't help. Please update your question with a corresponding sections of the code, because something is wrong here.

hoha
  • 4,418
  • 17
  • 15