【发布时间】:2019-12-08 12:16:32
【问题描述】:
我正在使用 iPhone7 模拟器。在我的屏幕中包含带有多个不同自定义单元格的 tableview。
当我最初加载这个屏幕时,我的 tableView 宽度是 375,cell.contentview 宽度是 320。
但是当我滚动这个屏幕时,tableview 宽度是 375,cell.contentview 宽度是 375。
//Custom Cell class
@interface CustomTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *lblTitle;
@end
@implementation CustomTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
self.contentView.backgroundColor = [UIColor whiteColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (void)loadData:(NSString *)data
{
self.lblTitle.text = data;
}
@end
//Viewcontroller class
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationItem.title = "profile"
[self.tableView reloadData];
}
//tableview delegate method called from my datasource class like
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
return [self.datasource cellForSection:indexPath.section row:indexPath.row];
}
//Datasource class
- (UITableViewCell *)cellForSection:(NSInteger)section row:(NSInteger)row {
CustomTableViewCell
*cell = [self.view cellForReuseIdentifier:[CustomTableViewCell
reuseIdentifierString]];
[cell loadData:self.userRepository.currentUser.id];
return cell;
}
如何解决这个问题?
【问题讨论】:
-
显示你的 UI 或相关代码
-
请显示您使用 tableView 委托的代码。也许您正在做一些 UI 更改或重绘或其他任何事情?
标签: ios swift iphone xcode uitableview