Un altro modo è quello di creare una cella personalizzato ed eseguire l'override layoutSubviews
metodo.
@interface CustomCell : UITableViewCell
@end
@implementation CustomCell
- (void)layoutSubviews
{
[super layoutSubviews];
// grab bound for contentView
CGRect contentViewBound = self.contentView.bounds;
// grab the frame for the imageView
CGRect imageViewFrame = self.imageView.frame;
// change x position
imageViewFrame.origin.x = contentViewBound.size.width - imageViewFrame.size.width;
// assign the new frame
self.imageView.frame = imageViewFrame;
}
@end
Rembember che in cellForRowAtIndexPath
è necessario creare e riutilizzare CustomCell
e non UITableViewCell
.
Spero che aiuti.
Modifica
#import "CustomCell.h"
// other code here...
- (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;
}
fonte
2012-02-25 16:48:36
temo che non è possibile con standar 'UITableViewCell' devi usare la tua cella e poi personalizzarla. – HelmiB