开发者

Question on how to add a UIview as a subview to a UITableCell

I've got a question on how to add a UIView to a UITableViewCell.

In my learning Project I've got a UITableViewController (TableTestViewController, a UITabelViewCell.xib (MainTabelCell.xib) and a UIView (InnerTableView). My Goal ist to show the MainTableCell in the UITableView and in this MainTabelCell the InnerTabelView but I only manage to show the Cell in the Table.

TableTestViewController.h:

#import <UIKit/UIKit.h>
#import "InnerTableView.h"

@interface TableTestViewController : UITableViewController {

    UITableView *mainTable;
    UITableViewCell *nibLoadedCell;
    InnerTableView *innerView;
}

@property(nonatomic, retain) IBOutle开发者_Go百科t UITableView *mainTable;
@property(nonatomic, retain) IBOutlet UITableViewCell *nibLoadedCell;
@property(nonatomic, retain) InnerTableView *innerView;

@end

TableTestViewController.m:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"MainTableCell"
            owner:self options:NULL]; 
        cell = nibLoadedCell;
    }

    // Configure the cell.
    innerView = [[UIViewController alloc] init];
    [cell addSubview: innerView.view];
    return cell;
}

Does anyone have an Idea why the innerView will not be shown in the TabelViewCell? What did I miss here? I'm still learning all that stuff but after 5 hours I don't find a clue in my Books. Hope this is not a to dumb question :)

Thank you

CaptnCrash


You should use [cell.contentView addSubview:yourView];

BTW, in your code, your innerView is not released properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜