4

I want to change the appearance of an UITableviewCell in edit mode like it is shown in the address book from apple. The cell should resize and i will add UITextFields as subviews. I know that to change appearance of a cell you have to overwrite the LayoutSubviews function in the cell. I tried to do that and i had some funny effects and resizing :-)

I have looked for a while to find some hints on the net but i didnt find one. If anyone could provide some hints how to do this right? Links to tutorials or code will be fine.

Thanks Eddy

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
Eddy
  • 41
  • 1
  • 2

4 Answers4

5

It's NOT a good idea to overwrite setEditing:animated: and reload your table view cells there. That is very resource-expensive, and not the right place to do it.

In the subclass of UITableViewCell, override method didtransitionToState: There, you can act directly on the cell outlets, like so :

    - (void)didTransitionToState:(UITableViewCellStateMask)state
    {
        [super didTransitionToState:state];

        if (state == UITableViewCellStateShowingEditControlMask) {
            // edit mode : peform operations on the cell outlets here

        } else if (state ==UITableViewCellStateDefaultMask) {
            // normal mode : back to normal
    }
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
Frederic Adda
  • 5,905
  • 4
  • 56
  • 71
  • I used the subclass method here to change the color of the UILabel within the cell when in debit mode. It worked great. – T.J. Feb 17 '14 at 20:51
0

If you want to resize the cells height you should also change "heightForRowAtIndexPath" in your UITableView Delegate. At least that is a thing I stumbled over a few times.

Maverick1st
  • 3,774
  • 2
  • 34
  • 50
  • thanks for the advice but my animation in layoutsubviews is wrong it changes the size of the cell but it moves all cells to one place for example or cuts the top of the cell...as i said very funny animatons when entering edit mode :-) – Eddy Mar 08 '11 at 12:43
  • So if your Code in layoutSubviews is wrong it might help if you show us the code so we can find the wrong part together. :) – Maverick1st Mar 08 '11 at 12:48
  • im not at home atm so i dont have the code here but what i do is something like: cell in edit mode..... self.frame = CGRectMake(x,y,w,h).... then all cells move animated to x y but change size like height :-)... how can i change frame wihtout moving.....when i am back home this evening i can provide my code. – Eddy Mar 08 '11 at 12:56
  • if you want to change height or width in your frame without moving just call: frame = CGRectMake(frame.origin.x, frame.origin.y, width, height); If you want to move your frame without beeing animated while moving just set a frame with the same height and width out of the animation block and change the size of the frame inside of the animation block. You should also watch for the correct coordinates of your frame. It might be that you have to transfer them to the coordinatesystem of the superview. – Maverick1st Mar 08 '11 at 13:03
  • ok thanks ill try this when ivam back home...i just want the same effect that occures when you are in the personview of the addressbook and you press edit :-) – Eddy Mar 08 '11 at 13:09
0

when you set myTable.editing=YES; it calls table view datasource and delegate method.

so if you have any data to display in table then the above code line calls the delgate method

so you can code here

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

        if(myTable.editing==YES)
        {
            return 70;//customize it.
        }
        return 50;

}
Ishu
  • 12,797
  • 5
  • 35
  • 51
  • 4
    By default this is not called when you switch table to editing mode. this requires to call method reloadData on tableview. If you call reload data the editing animation goes away. – Kunal Balani Jul 21 '14 at 22:07
  • This actually works. Just set the height of your cell in this method and it will work. (Unless you want the editing animation). – Sebyddd Aug 29 '14 at 13:45
0

Overwrite setEditing:animated: and reload your table view cells there.

Anh
  • 6,523
  • 7
  • 46
  • 59