Meh*_*san 5 objective-c uitableview ios autolayout
我遵循/sf/answers/1312285131/中提到的概念,但稍微以不同的方式使用自动布局实现动态单元格.我只有一个原型自定义单元格.但我必须根据数据阵列向单元格添加多个UILabel,并且必须保持动态单元格高度.
//我的UITableViewCell
@interface CustomCell ()
@property (nonatomic, assign) BOOL didAddLabel;
@end
@implementation CustomCell
- (void)awakeFromNib {
[super awakeFromNib];
}
-(void)addLabel:(NSArray*)someAry{
if(!didAddLabel){
for (int i=0; i<someAry.count; i++) {
// Initialize UILabel Programtically ...
// adding label
[self.aViewOfContaintView addSubview:aLabel];
}
self.heightLayoutConstraintOfaViewOfContaintView.constant = value;
[self.aViewOfContaintView layoutIfNeeded];
self.didAddLabel = YES;
}
}
@end
Run Code Online (Sandbox Code Playgroud)
//我的UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
//.. .. ..
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 100;
//.. .. ..
}
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = (CustomCell *)[theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell for this indexPath
//.. .. ..
//Add Label
[cell addLabel:anAry];
[cell layoutIfNeeded];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
如果我不使用那个检查didAddLabel,那么滚动表粘贴.如果我使用它,那么我只得到四个不同高度的细胞.
上面的回答提到"对于小区中每个唯一的约束集,使用唯一的小区重用标识符......."
如何使用/注册不同的重用标识符到同一个自定义单元?任何替代解决方案或任何帮助将不胜感激.
| 归档时间: |
|
| 查看次数: |
921 次 |
| 最近记录: |