gpt4 book ai didi

ios - 最后两个单元格之间奇怪的 UITableViewCell 间隙

转载 作者:行者123 更新时间:2023-12-01 16:37:52 30 4
gpt4 key购买 nike

我有一个自定义 UITableViewCell Card 样式的动态高度,它的空间在应用程序中是恒定的。我正在使用 Storyboard ,并且在 UINavigationBar 下方有 UIToolbar。

enter image description here

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (!_listOfMessages) {
return 0;
}
else if (_unreadMessages && [self.segmentControl selectedSegmentIndex] == 0)
return _unreadMessages.count;
else
return _listOfMessages.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
WCFeedItem *item;

if ([self.segmentControl selectedSegmentIndex] == 0) {
item = _unreadMessages[indexPath.row];
}
else {
item = _listOfMessages[indexPath.row];
}

RKCardInboxCell *cell = (RKCardInboxCell *)[tableView dequeueReusableCellWithIdentifier:@"RKCardInboxCell"];

// Configure the cell...
if (cell == nil) {
cell = [[RKCardInboxCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"RKCardInboxCell"];
}
else {
[[[cell.contentView viewWithTag:99] viewWithTag:97] removeFromSuperview];
cell.cardView.backgroundColor = [UIColor whiteColor];
}

[cell layoutSubviews];

[cell.profileImage setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:item.person.avatar_feed]] placeholderImage:[UIImage imageNamed:@"loading"] success:
^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
cell.profileImage.image = image;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
}];

[cell setItem:item];


cell.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.titleLabel.numberOfLines = 0;

CGRect expectedLabelSize = [item.summary boundingRectWithSize:CGSizeMake(268, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:cell.titleLabel.font}
context:nil];

// NSLog(@"size %@", NSStringFromCGSize(expectedLabelSize.size));
CGRect newFrame = cell.titleLabel.frame;
newFrame.size.height = expectedLabelSize.size.height;
cell.titleLabel.frame = newFrame;

cell.titleLabel.text = item.summary;
cell.nameLabel.text = item.person.name;
cell.descriptionLabel.text = item.messageTo;
[cell.timeButton setTitle:item.date forState:UIControlStateNormal];

if (item.isUnseen) {
cell.cardView.backgroundColor = [UIColor colorWithRed:0.94 green:0.97 blue:1 alpha:1];

UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(10,20,10,10)];
circleView.alpha = 0.5;
circleView.layer.cornerRadius = 5;
circleView.backgroundColor = [UIColor colorWithRed:0 green:0.2 blue:0.4 alpha:1.0];
circleView.tag = 97;
CGRect timeLabel = [[cell.contentView viewWithTag:99] viewWithTag:98].frame;
circleView.center = CGPointMake((timeLabel.origin.x + timeLabel.size.width) - circleView.frame.size.width, timeLabel.origin.y + timeLabel.size.height + circleView.frame.size.height);
[[cell.contentView viewWithTag:99] addSubview:circleView];
//[cell bringSubviewToFront:circleView];
}


cell.cardView.frame = CGRectMake(10, 5, 300, 160-8+expectedLabelSize.size.height-5);

return cell;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

UIFont *font = [UIFont systemFontOfSize:13];

NSString *aboutText = [_listOfMessages[indexPath.row] summary];


// ios 7 only
CGRect boundingRect = [aboutText boundingRectWithSize:CGSizeMake(268, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:font}
context:nil];

CGSize boundingSize = boundingRect.size;
// end ios7 only

// [cardSizeArray addObject:[NSNumber numberWithInt:160-8+boundingSize.height]];

return (160-8+boundingSize.height);
}

最佳答案

是因为cardView宽 300 点,但 heightForRowAtIndexPath使用268点?看起来有问题的行的文本可能会在 268 处换成两行,但在 300 处只有一行。没有看到 RKCardInboxCell 的布局代码很难确定。

顺便说一句,像这样的硬编码宽度将难以支持更宽的设备,如 iPhone 6 和 6 Plus。

关于ios - 最后两个单元格之间奇怪的 UITableViewCell 间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26591939/

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