问题
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
回答1:
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
}
回答2:
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;
}
回答3:
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.
回答4:
Overwrite setEditing:animated: and reload your table view cells there.
来源:https://stackoverflow.com/questions/5232386/uitableviewcells-change-size-in-edit-mode