如何以编程方式显示UITableView? [英] How to display the UITableView programmatically?

查看:78
本文介绍了如何以编程方式显示UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个关于目标C的UITableView的问题。我正在编写一个程序,我想以编程方式创建UI。但是,我不知道如何以编程方式显示表。我已经有一个NSMutableArray来存储显示的数据。我创建了一个对象 UITableView * tableData; ,我该怎么办呢?非常感谢。

I want to ask a question about the UITableView of the objective C. I am writing a program and I would like to create the UI programmatically. However, I don't know how to display the table programmatically. I already have a NSMutableArray to store the displayed data. And I create a object UITableView *tableData;, what should I do for the next step? Thank you very much.

推荐答案

编写完上面代码后,你必须实现UITableView的委托方法。

after writing above code you have to implement delegate method of UITableView.

这些是UITableView加载的委托方法

these are delegate method of UITableView load

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [your array count];
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    // Configure the cell...
    cell.textLabel.text = [yourarray objectAtIndex:indexPath.row];

    return cell;

}

这篇关于如何以编程方式显示UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆