Nikunj Jadav
Nikunj Jadav

Reputation: 3402

iPhone:TableView cellForRowAtIndexPath method issue

I am facing a crashing problem in cellForRowAtIndexPath tableview delegate method

@interface EventListView : UIViewController <UITableViewDelegate, UITableViewDataSource> 

IBOutlet UITableView *tblView;
NSMutableArray  *arr_EventValues,*arr_Event_Details;
NSMutableArray  *arr_EventListDetails;

@property(nonatomic, retain)NSMutableArray *arr_EventValues,*arr_EventListDetails, *arr_Event_Details; 
@property(nonatomic, retain)UITableView *tblView;

- (void)viewDidLoad  
{
     appdelegate = (VibesGuideAppDelegate *)[[UIApplication sharedApplication] delegate];
     ViewCalendar = [[CalendarView alloc] initWithNibName:@"CalendarView" bundle:[NSBundle mainBundle]];
     [self.navigationController.navigationBar setHidden:YES];
     self.arr_Event_Details = [[NSMutableArray alloc] init]; 
     self.arr_EventValues = [[NSMutableArray alloc] init];
     [super viewDidLoad];
}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
     return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
     if ([self.arr_EventListDetails count] > 0)
     {
         return [self.arr_EventListDetails count];
     }
    return 0;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    // ------------------------------- Custom cell ------------------------------
    Customcell  *cell = (Customcell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

     cell = [[[Customcell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

     cell.textLabel.text = @"Hello";    
     return cell;
 }

* -[EventListView tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x60e01b0 and I used tableview from xib and set all connections and also got arrayvalues in numberOfRowsInSection in method but in cellForRowAtIndexPath method is not called so please give me idea my issue....

Thanks in advance.

Upvotes: 0

Views: 1839

Answers (4)

alinoz
alinoz

Reputation: 2822

First of all you dequeue the cell and then create a new one. This is not a good practice, if you are able to dequeue a cell you should not create a new one. You should have something like this:

 Customcell  *cell = (Customcell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

 if(cell == nil)
 {
     cell = [[[Customcell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
 }

fix this and let me know if you are still running on the same problem.

Upvotes: 0

TheEye
TheEye

Reputation: 9346

Your tableview itself is already released - the error message says that you send the cellForRowAtIndexPath message to a deallocated instance of the table view - so your problem lies somewhere in not retaining or releasing the EventListView and cannot be seen in the code displayed here.

Upvotes: 2

Himanshu A Jadav
Himanshu A Jadav

Reputation: 2306

At first it seems your some variable gets released. Make sure you have properly allocated it. If you have declared @property for it you better use the variable as self.variable. You can use retain and in case of IOS 5 strong in property declaration.

Just to be sure you can track if any variable gets released via setting NSZombieEnabled to YES. With zombies enabled, messages to deallocated objects will no longer behave strangely or crash in difficult-to-understand ways, but will instead log a message and die in a predictable and debugger-breakpointable way. You can set NSZombieEnabled by the following steps.

Select Product from the menu bar above. Keep alt/option pressed and select "Test..." or "Run...". Go to the Arguments tab, and add NSZombieEnabled YES in the "Environment Variables" section.

Upvotes: 2

Sudesh Kumar
Sudesh Kumar

Reputation: 569

Check this one:

Table DataSource and delegate is set or not. Used array in cellForRowAtIndexPath is properly set with property and synthesized as well used with self. name.

Upvotes: 0

Related Questions