Michel
Michel

Reputation: 11749

UITableView / setEditing

I have the following problem with UITableView and setEditing.

The first time the view appears everything seems perfect. The second time it crashes on the line:

[myList setEditing:YES animated:YES];

with a message like:

[1143:207] *** -[__NSArrayM count]: message sent to deallocated instance 0xb204700

in the debugger console.

I include here the two relevant pieces of code:

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    myList=[[UITableView alloc] initWithFrame:CGRectZero];
    [myList addGestureRecognizer:swipeRecognizer];
    myList.backgroundColor=[UIColor colorWithRed:0.82 green:0.82 blue:0.82 alpha:0.6];
    myList.dataSource=self;
    myList.delegate=self;
    [myList setEditing:YES animated:YES];
    ………
}


- (void)viewDidDisappear:(BOOL)animated {
    [myList removeGestureRecognizer:swipeRecognizer];
    [myList removeFromSuperview];
    [myList release];
    myList=nil;
    [super viewDidDisappear:animated];
}

Since this is my first time to use UITableView and setEditing, I might be missing something obvious.

Anyone can see something suspicious in my code?

Upvotes: 0

Views: 463

Answers (1)

MikecheckDev
MikecheckDev

Reputation: 2494

I'm guessing that you have a method that looks like the following:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [self.someArray count];
}

You need to make sure that the "someArray" variable is still around. If your array is in your .h file, make sure you are using

@property (nonatomic, retain) NSArray *array;

or (if you are using ARC)

@property (nonatomic, strong) NSArray *array;

Can you post the contents of this method? (or the complete contents of both your .h and .m file)

Upvotes: 1

Related Questions