UIMutableIndexPath release for UITableView reloadData - ios

I sometimes get a crash with this error [UIMutableIndexPath release]: message sent to deallocated instance 0x205a2930 when I try to execute :
[self.detailsTableView reloadData];
The cellForRowAtIndexPath method is here :
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DetailResultCell *cell = (DetailResultCell*) [aTableView dequeueReusableCellWithIdentifier:DETAIL_RESULT_CELL_ID];
if(cell == nil)
{
[[NSBundle mainBundle]loadNibNamed:DETAIL_RESULT_CELL_ID owner:self options:nil];
cell = detailResultCell;
}
cell.detailsResultatViagerViewController = self;
[cell cellWithIndexPath:indexPath andChamp:[[self.resultats objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
return cell;
}
How can I avoid this ? I try to put a try/catch block around the [self.detailsTableView reloadData]; but the crash still happens...

Related

ios tableViewCell.xib file generate more than one cell

- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:#"FriendTableViewCell" bundle:nil] forCellReuseIdentifier:#"FIDCELL"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"FIDCELL"];
return cell;
}
This code block work but when i add new cell in FriendTableViewCell.xib not work actually i can not call new cell. How can i call this cell or this is possible ? If this question is not clear i can add image...
**
i try to call different cell from same .xib
**
Error:
I found solution i generate new .xib and call when page load both of them
[self.tableView registerNib:[UINib nibWithNibName:#"FriendTableViewCell" bundle:nil] forCellReuseIdentifier:#"FIDCELL"];
[self.tableView registerNib:[UINib nibWithNibName:#"Cell2" bundle:nil] forCellReuseIdentifier:#"FIDCELL2"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellID = #"";
if (indexPath.row % 2 == 0) {
cellID = #"FIDCELL";
} else {
cellID = #"FIDCELL2";
}
FriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
// Configure the cell...
cell.nameLabel.text = self.namesArray[indexPath.row];
cell.photoImageView.image = [UIImage imageNamed:self.photoNameArray[indexPath.row]];
return cell;
}
This code part totally work.
Okey so first of all , every cell should have its unique identifier so if the first cell have an identifier called "FIDCELL" the second one should have another one called "FIDCELL2" for example , and remove the following line from your viewDidLoad :
[self.tableView registerNib:[UINib nibWithNibName:#"FriendTableViewCell" bundle:nil] forCellReuseIdentifier:#"FIDCELL"];
and add this to cellForRowAtIndexPath
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell * cell ;
if(condtion1)
{
cell = [tableView dequeueReusableCellWithIdentifier:firstCellIdentfier];
}
else if(condtion2)
{
cell = [tableView dequeueReusableCellWithIdentifier:secondCellIdentfier];
}
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:yourNibName owner:self options:nil];
if(condtion1)
{
//0 is the index of the first cell in the nib
cell = [nib objectAtIndex:0];
}
else if(condtion2)
{
//1 is the index of the second cell in the nib .
cell = [nib objectAtIndex:1] ;
}
}
//do other work
return cell ;
}
where condtion1 and and condtion2 is the conditions that will determine which cell will be chosen .

Customize a tableview

I have a tableview which shows data. But i want to customize the cells and i need a little help. So i have a nib for the tableview (HistoryViewController.xib). I just added the class and nib to customize the tableview cells (HistoryViewTableCell).
What are the steps i have to do next? I have this code already:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"TableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSDictionary * tempDictionary = [tableData objectAtIndex:indexPath.row];
cell.textLabel.text = [tempDictionary objectForKey:#"PickupAddress"];
return cell;
}
Try this link ..
Custom UITableViewCell Using Interface Builder
good demo with project try this
Customize Table View Cells for UITableView
hope it helps.
Please try below code -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HistoryViewTableCell *cell = [tableView dequeueReusableCellWithIdentifier:#"HistoryViewTableCell"];
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:#"HistoryViewTableCell" bundle:nil];
// Grab a pointer to the custom cell.
cell = (HistoryViewTableCell *)temporaryController.view;
}
return cell;
}
OR
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HistoryViewTableCell *cell = [tableView dequeueReusableCellWithIdentifier:#"HistoryViewTableCell"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"HistoryViewTableCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
}

UITableViewCell and allocation problems

I want to use a custom reusable UITableViewCell with my UItableview, it works but, testing with instruments - allocation, I see that memory is not released when I get out of my UIViewController and re-enter several times.
here are the three methods that i've tried,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// method #1
static NSString *CellIdentifier2 = #"customClassicCell";
customClassicCell *cell = (customClassicCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"customClassicCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[customClassicCell class]])
{
cell = (customClassicCell *)currentObject;
break;
}
}
}
return cell;
}
or
static NSString *cellIdentifier44 = #"custom44";
- (void)viewDidLoad {
[self.tbv registerNib:[UINib nibWithNibName:#"customClassicCell" bundle:nil] forCellReuseIdentifier:cellIdentifier44];
[super viewDidLoad];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// method #2
customClassicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier44];
return cell;
}
or
// method3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier44];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier44] ;
}
return cell;
}
instrument shows this (every times I get out and get in my UIviewcontroller), it's the same problem with the 3 methods, memory is not correctly released.
I use xcode 5.0 target 5.1
I do not use ARC neither storyboards. Anyone has an idea ?

cellForReloadIndexPath not getting called on reloadData

Ive read through the other posts and cant seem to figure it out. cellForRowAtIndexPath does get called when I scroll over to previously unviewed cells, but when i call reloadData it doesnt get called. Delegate is hooked up to files owner, as is data source.
my cellForRowAtIndexPath:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)cellForRowAtIndexPath {
NSLog(#"cellForRowAtIndexPath");
static NSString *CellTableIdentifier = #"CellTableIdentifier";
UINib *nib = [UINib nibWithNibName:#"HBStopDialogCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:CellTableIdentifier];
HBStopDialogCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
NSUInteger row = [cellForRowAtIndexPath row];
[cell stopName:ourStop.stopName stopLine:[ourStop.normalStopsArray objectAtIndex:row]];
if (cell==nil) {
NSLog(#"ah the cell is nil");
}
return cell;
}

I got a signal SIGABRT and a log message

I tried to run my app and I got signal SIGABRT in the Main.m file and this log message. Help?
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '- [UITableViewController loadView] loaded the "5wY-6u-SFr-view-Zew-TR-1Cy" nib but didn't get a UITableView.'
*** First throw call stack:
(0x15d3052 0x1764d0a 0x157ba78 0x157b9e9 0x2536ae 0xea5cb 0xf358c 0xee3e8 0x307cc5 0xf1427 0xf158c 0xb6f5280 0xf15cc 0x4546b6 0x448e30 0x15d4ec9 0x275c2 0x2755a 0xccb76 0xcd03f 0xcc2fe 0x4ca30 0x4cc56 0x33384 0x26aa9 0x14bdfa9 0x15a71c5 0x150c022 0x150a90a 0x1509db4 0x1509ccb 0x14bc879 0x14bc93e 0x24a9b 0x1d42 0x1cb5)
terminate called throwing an exception
Here is the code for my table view:
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.menu count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[self.menu objectAtIndex:indexPath.row]objectForKey:#"Title"];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"detailViewController"bundle:nil];
OrderViewController *orderViewController = [[OrderViewController alloc] initWithNibName:#"orderViewController"bundle:nil];
detailViewController.item = [self.menu objectAtIndex:indexPath.row];
orderViewController.itemString = [self.menu objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
}
I have seen same problem as mentioned by Hot Licks. My xib file got corrupted. You can define corruption of xib as for example, a control is wired to more than one actions, or wired with couple of ivars. Obviously, by mistake.
Fastest thing to check your xib file,right click on control and see whether it has more than one association.

Resources