TableViewCell.Xib Class DyanamicCells ..
In TableViewCell.xib do small Autolayout just give 4 constraints to dataLabel....
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@end
#import "ViewController.h"
#import "TableViewCell.h"
@interface ViewController ()
{
NSString *tempStr;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
tempStr = @"Creating UITableViewCells with dynamic height based upon Auto Layout constraints is actually an easy job once you figured out what's required to make this work. This blog post will briefly explain how to create a UITableViewCell in which height is calculated dynamically by the UITableView depending on what content it contains.";
_tableView.estimatedRowHeight = 140.0;
_tableView.rowHeight = UITableViewAutomaticDimension;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
# pragma mark - Cell Setup
- (void)setUpCell:(TableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.text = tempStr;
}
# pragma mark - UITableViewControllerDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
[tableView registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
cell.dataLabel.text = tempStr;
return cell;
}
@end
@interface TableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *dataLabel;
@end
#import "TableViewCell.h"
@implementation TableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
No comments:
Post a Comment