I have a problem with a UITableView. I included 2 photos a before and after to help illustrate the problem better. The tableView performs like it is supposed to until I delete a row from section 0. When it reloads the tableview the the 'detailTextLabel' which should have been deleted show up in section 1 of that tableview.
Out of the 3 sections in that tableview only section 0 should have a detailedTextLable. But you can see that after I delete a row from section 0 it reloads incorrectly.
If I stop the program and restart it everything loads in the way it should. I think the problem has to do with the reload of the stored cells. Depending on what section is selected I create ether a UITableViewCellStyleDefault or UITableViewCellStyleSubtitle
I did solve this problem but the way I solved it I know is wrong (this code is before my solved code). When the view is entered again, in the Method viewWillAppear I remove the tableview from the superview and re initilize a new tableview with the same name and everything load just fine. But I should not have to do that.
Is there a way to just delete the whole index that stores the cell so it can create a new NSIndex from scratch populates the new tableview?
Out of the 3 sections in that tableview only section 0 should have a detailedTextLable. But you can see that after I delete a row from section 0 it reloads incorrectly.
If I stop the program and restart it everything loads in the way it should. I think the problem has to do with the reload of the stored cells. Depending on what section is selected I create ether a UITableViewCellStyleDefault or UITableViewCellStyleSubtitle
I did solve this problem but the way I solved it I know is wrong (this code is before my solved code). When the view is entered again, in the Method viewWillAppear I remove the tableview from the superview and re initilize a new tableview with the same name and everything load just fine. But I should not have to do that.
Is there a way to just delete the whole index that stores the cell so it can create a new NSIndex from scratch populates the new tableview?
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[COLOR="Red"]cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];[/COLOR]
cell.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.3];
}
if (tableView == staticSkillsTableView) {
cell.textLabel.text = [staticSkills objectAtIndex:indexPath.row];
int x = [[staticSkills objectAtIndex:indexPath.row]length];
if (x > 18) {
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
}
else{
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:18];
}
}
if (tableView == battleTableView) {
if (indexPath.section == 0) {
NSDictionary *getLevel = [characterLoadInfo objectForKey:@"combatroundsSaved"];
NSDictionary *getname = [NSDictionary dictionaryWithDictionary:[getLevel objectForKey:[nameArrayForTableView objectAtIndex:indexPath.row]]];
NSString *level = [NSString stringWithString:[getname objectForKey:@"level"]];
[COLOR="Red"]cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];[/COLOR]
cell.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.3];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [NSString stringWithFormat:[nameArrayForTableView objectAtIndex:indexPath.row], indexPath.row];
cell.detailTextLabel.text = [detailedNameArrayForTableView objectAtIndex:indexPath.row];
if ([level isEqualToString:@"0"]) {
[COLOR="Red"] cell.detailTextLabel.textColor = [UIColor redColor];[/COLOR]
}
else{
[COLOR="Red"] cell.detailTextLabel.textColor = [UIColor blackColor];[/COLOR]
}
}
}
if (indexPath.section == 1) {
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [NSString stringWithFormat:[usedSkillsArray objectAtIndex:indexPath.row], indexPath.row];
}
if (indexPath.section == 2) {
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:20];
NSString *itemName = [NSString stringWithFormat:[itemListArray objectAtIndex:indexPath.row], indexPath.row];
NSArray *itemBonusArray = [NSArray arrayWithArray:[itemListDict objectForKey:itemName]];
NSString *itemBonus = [NSString stringWithFormat:@"%@", [itemBonusArray objectAtIndex:0]];
if (![itemBonus isEqualToString:@"0"]) {
NSString *writeToCell = [NSString stringWithFormat:@"%@ +%@",itemName, itemBonus];
cell.textLabel.text = writeToCell;
}
else{
NSString *writeToCell = [NSString stringWithFormat:@"%@",itemName];
cell.textLabel.text = writeToCell;
}
}
return cell;
}
Attachments
Last edited: