views:

41

answers:

2

I have subclassed a tableview cell and added a couple of labels and images to the custom cell.

   [self.contentView addSubview:lblDesc];
   [self.contentView addSubview:imagesToDisplay];

When i edit the tableView and press the "-" sign the delete button appears on top of the image and other contents.

Some other apps squeeze the contents of the cell to accomodate the delete button.

How do i go about doing this??

Do i need to add a key value Observer [cell addObserver: self forKeyPath: @"showingDeleteConfirmation" options: NSKeyValueObservingOptionNew context: NULL];

A: 

You need to set the proper autoresizingMask so that your button moves properly when the contentView changes size.

St3fan
Nope. I added this in my custom implementation and also in the tableview delegate method. But dint make a difference.
BK
ok got this to work, i need to set the autoresizingMask of the labels and images. But they labels and images overlap now. Tried all sorts of combinaitons.
BK
+1  A: 

Autoresizing is simple - think of it like a web page. Web content "flows", it takes up as much space as the browser window gives it. Autoresizing is the same. There are "masks" which tells UIKit how you want your content to adjust to different frame sizes.

So, for example, if you want your view to shrink or grow from the right side (if it were, for example, left-justified content like a table cell), you'd set the mask like this:

cell.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;

Autoresizing also works like a bitwise-OR operation, so if you want it to grow from the right (as above) but also grow from the bottom, you'd "OR" the two together.

cell.autoresizingMask = (UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin);

In the case that this does not work for you (e.g. you want to put too much on the screen, and need to remove certain elements, etc, or you want to animate somehow differently than the default), consider using the pre-existing method calls in UITableViewCell. From the documentation:

- (void)willTransitionToState:(UITableViewCellStateMask)state

This will be called right before the cell changes state (normal->editing or the other), so if you need to do anything special to handle the animation to the editing state, this is your opportunity to do so. The docs state:

Subclasses of UITableViewCell can implement this method to animate additional changes to a cell when it is changing state. UITableViewCell calls this method whenever a cell transitions between states, such as from a normal state (the default) to editing mode. The custom cell can set up and position any new views that appear with the new state. The cell then receives a layoutSubviews message (UIView) in which it can position these new views in their final locations for the new state. Subclasses must always call super when overriding this method.overriding this method.

phooze
ok so this requires me to do the "dirty" work. I would prefer not to use this, cos I have some 7 different types of cells so i would have to do a lot of customization. But then again if everything else fails i will look into it. But it would be nice if u could shed some light on the autoresizingMask "way".Its not working for me.
BK
I added more about autoresizing. Also, try having a look at Apple's sample code for AdvancedTableCells - http://developer.apple.com/library/ios/samplecode/AdvancedTableViewCells/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009111
phooze
hey thanks for the autoresizing stuff, and i guess i need to use ur first solution itself, lot of clutter on my table cell.
BK