在单击或来回滚动单元格之前,自定义UITableView单元格不会加载

时间:2014-09-03 19:15:37

标签: objective-c xcode uitableview nib

- (void)viewDidLoad
{
[super viewDidLoad];
// Register the nibs

UINib *tNIb = [UINib nibWithNibName:@"textFieldNib" bundle:nil];
[self.tableView registerNib:tNIb forCellReuseIdentifier:@"textCell"];

UINib *dNib = [UINib nibWithNibName:@"descriptionNib" bundle:nil];
[self.tableView registerNib:dNib forCellReuseIdentifier:@"descriptionCell"];

UINib *iNib = [UINib nibWithNibName:@"imageNib" bundle:nil];
[self.tableView registerNib:iNib forCellReuseIdentifier:@"imageCell"];

UINib *lNib = [UINib nibWithNibName:@"labelNib" bundle:nil];
[self.tableView registerNib:lNib forCellReuseIdentifier:@"labelCell"];

NSLog(@"%@ %@ %@", self.collegeString, self.presidentString, self.membersString);


}

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

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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"  forIndexPath:indexPath];
_textCell = (textFieldCell *) [self.tableView dequeueReusableCellWithIdentifier:@"textCell"];
_descriptionCell = (descriptionCell *) [self.tableView   dequeueReusableCellWithIdentifier:@"descriptionCell"];
_imageCell = (imageCell *) [self.tableView dequeueReusableCellWithIdentifier:@"imageCell"];
_labelCell = (labelCell *) [self.tableView dequeueReusableCellWithIdentifier:@"labelCell"];

[_textCell.contentView.superview setClipsToBounds:NO];
[_descriptionCell.contentView.superview setClipsToBounds:NO];
[_imageCell.contentView.superview setClipsToBounds:NO];
[_labelCell.contentView.superview setClipsToBounds:NO];
[cell.contentView.superview setClipsToBounds:NO];

if (indexPath.section == 0) {
    _labelCell.collegeLabel.text = self.collegeString;
    _labelCell.presidentLabel.text = self.presidentString;
    _labelCell.membersLabel.text = self.membersString;
    return _labelCell;
}
if (indexPath.section == 1) {
    return _imageCell;
}
if (indexPath.section == 2) {
    return _descriptionCell;
}
if (indexPath.section == 3) {
    return _textCell;
}

return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
    return 113;
}
if (indexPath.section == 1) {
    return 134;
}
if (indexPath.section == 2) {
    return 110;
}
if (indexPath.section == 3) {
    return 100;
}
else{
    return 90;
}

}

我的所有自定义单元格都会加载,但只有在我单击一个单元格几次或向上和向下滚动tableView之后。当我运行没有-tableView heightForRowAtIndexPath方法的应用程序时,单元格立即加载。所以它与该方法有关,但我不知道如何改变每个单元格的高度。

0 个答案:

没有答案