Another way is to create a custom cell and override the method layoutSubviews.
@interface CustomCell : UITableViewCell
@end
@implementation CustomCell
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect contentViewBound = self.contentView.bounds;
CGRect imageViewFrame = self.imageView.frame;
imageViewFrame.origin.x = contentViewBound.size.width - imageViewFrame.size.width;
self.imageView.frame = imageViewFrame;
}
@end
Enter what cellForRowAtIndexPathyou need to create and reuse in CustomCell, not UITableViewCell.
Hope this helps.
Edit
#import "CustomCell.h"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
source
share