I created a UITableViewCell
in Xcode 4 using IB. But for some weird reason when I trigger my edit button, the cell
acts really weird and doesn't have the same animations as a normal table view cell. I don't know what is happening, I tried implementing -(void)setEditing:(BOOL)editing animated:(BOOL)animated
in my custom cell class but still nothing works.
UPDATE: My ViewController
that I am using the cell in, has this code under cellForAtIndex
to display the cell.
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell *) currentObject;
break;
}
return cell;
}
}
Normal view:
When tapping edit button:
And even when swiping it covers the text when it's supposed to move it aside:
First suggestion; don't use IB for custom
UITableViewCell
s.Next; make sure you're adding any custom views to the
UITableViewCell
'scontentView
... not just the cell itself. When the editing portions are shown (like the delete button) theUITableViewCell
's contentView will shrink automatically. If you have the correct UIViewAutoresizing mask on theUILabel
/ whatever you've added to thecontentView
, it will get resized / moved correctly.Edit, to answer your question in comments:
The same way you would any custom view. You could make it a class on it's own, or, depending on your needs, construct it ad-hoc. A class is usually best so you can reference any of your custom things you've added to the cell and reuse cells / etc.
But, here's is an example of constructing one ad-hoc.
Edit #2