How do I stop my custom cell from changing style after I leave a "setEditing" call?

StackOverflow https://stackoverflow.com/questions/19191616

  •  30-06-2022
  •  | 
  •  

Pergunta

I have a custom cell set up in xCode4.6. The cell looks great, until I try to edit/delete a cell. I am using .xib and the table is set to a default style.

So to recap: If I call the onClick function everything still looks great, it's when I call the onDoneClick, that the styling gets all messed up; however, if I were to click the onClick again, the styling looks good again.

Thanks for any help!

Here are the two buttons that call the setEditing.

-(IBAction)onClick:(id)sender
{
editBttn.hidden = true;
doneBttn.hidden = false;
[_tableView setEditing:YES animated:YES];
}

-(IBAction)onDoneClick:(id)sender
{
[_tableView setEditing:NO animated:YES]; 
editBttn.hidden = false;
doneBttn.hidden = true;
}
Foi útil?

Solução

One simplest solution is all a subview inside the tableviewcell so that in edit mode the alignment wont get change.

Follow this steps: 1. In your custom cell xib add a uiview(subView) and of course your tableviewcell(cell). 2. Add all uicontrols to uiview not in tableviewcell. 3. put in iboutlet of uiview in tableviewcell custom class.

This was for custom cell

now in cellForRowAtIndexPath: add this uiview as subview of cell

NSString *cellIdentifier=@"cell";
                CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
                if (cell == nil) {
                    // Load the top-level objects from the custom cell XIB.
                    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellXIB" owner:self options:nil];  
                    cell = [topLevelObjects objectAtIndex:0];
                    [cell addSubview:cell.subView];
                } 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top