将UITableVIew添加到视图

时间:2015-03-25 15:41:27

标签: ios objective-c uitableview uiview

当用户点击按钮时,我会在UIView中滑动(此UIVIew是通过XIB文件创建的。)

我在此TableView文件中添加了XIB,并且还连接了datasourcedelegate。见下图:

enter image description here

在View类中,我添加了以下方法。

-(id)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];

    [self addSubview:self. tablev];

}

在Header文件中,我有以下代码。

@interface FlipView : UIView <UITableViewDataSource,UITableViewDelegate>

UIViewController类的代码。此课程中有一个按钮,当用户点击它时,UIView会显示。单击按钮时将执行的代码。

fv = [[FlipView alloc] initWithFrame:cell.bounds];

[self.view addSubview:fv];

[self.view addSubview: fv];

view与tableview完美搭配。但是,不会填充tableview上的内容。当我调试代码时,我发现没有调用委托方法。我该如何解决这个问题?

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

    MyCell

 *cell = [tableView dequeueReusableCellWithIdentifier:@"c" forIndexPath:indexPath];

    if (cell == nil)

    {

        cell = [[MyCell

 alloc] initWithStyle:UITableViewCellStyleSubtitle

                                             reuseIdentifier:@"c"];

    }

    cell.la.text=@"hiiiii";

1 个答案:

答案 0 :(得分:0)

数据源和代理连接到文件的所有者, NOT 连接到FlipView。您可以从xib中删除委托和数据源,并以编程方式添加它:

self.tableView.delegate = self;
self.tableView.dataSource = self;

我建议在initWithFrame方法中执行此操作。