gpt4 book ai didi

objective-c - UITableViewCell accessoryType位置随单元格高度变化

转载 作者:太空狗 更新时间:2023-10-30 03:34:37 24 4
gpt4 key购买 nike

我用不同高度的单元格制作了一个 UITableView。在每个单元格上,我附加了一个 accessoryView (UIImageView)。

根据cell的高度,accessoryType位置不同(见附图)。我该如何纠正它?

在任何表格 View 中似乎都是正常的。没有找到答案。

感谢您的帮助。 http://i.stack.imgur.com/kKOn0.png

更新:我的 cellForRowAtIndexPath:

NSDictionary *currentTime = [listOfTimes objectAtIndex:indexPath.row];


UITableViewCell *cell;
if([[currentTime objectForKey:@"freq"] intValue] > 0) cell = [self getCellFreqContentView:@"CellFreq"];
else cell = [self getCellContentView:@"Cell"];

[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];

UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];

if([[currentTime objectForKey:@"freq"] intValue] > 0) {

lblTemp1.text = [NSString stringWithFormat:@"%@\n\n%@", [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSinceReferenceDate:[[currentTime objectForKey:@"arrival_time_seconds"] doubleValue]]],[dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSinceReferenceDate:[[currentTime objectForKey:@"departure_time_seconds"] doubleValue]]]];

UILabel *lblTemp3 = (UILabel *)[cell viewWithTag:3];
UILabel *lblTemp4 = (UILabel *)[cell viewWithTag:4];
lblTemp3.text = @"↓";
lblTemp4.text = [NSString stringWithFormat:NSLocalizedString(@"A pass every %i minutes", nil), [[currentTime objectForKey:@"freq"] intValue]/60];
} else {
lblTemp1.text = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSinceReferenceDate:[[currentTime objectForKey:@"departure_time_seconds"] doubleValue]]];
}

lblTemp2.text = [currentTime objectForKey:@"trip_headsign"];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

UIView *vv = [[UIView alloc] initWithFrame:cell.frame];
if(indexPath.row == [ScheduleManager getRowForTime:listOfTimes] && isCurrentPeriod == TRUE) {
vv.backgroundColor = [BKColor colorWithHexString:@"54B8BB"];
}

// SPECIAL CASES
if([[currentTime valueForKey:@"runoff"] count] > 0 && useExceptions == TRUE) {
// ACCESSORY
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"times-special.png"]];
}

cell.backgroundView = vv;

return cell;
}

最佳答案

我认为 accessoryView 的位置使得与右边缘、顶部边缘和底部边缘的距离以某种方式相关,因此您必须重新定位它。

可能最好的方法是子类化 UITableViewCell,并覆盖 layoutSubviews 方法:

- (void)layoutSubviews {
[super layoutSubviews];
CGRect accessoryFrame = self.accessoryView.frame;
accessoryFrame.origin.x = <desired position here>;
self.accessoryView.frame = accessoryFrame;
}

关于objective-c - UITableViewCell accessoryType位置随单元格高度变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6791391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com