iphone - 我如何在 Xcode 4.2 上为 IOS 5 创建一个 UITableView?

标签 iphone c++ xcode uitableview ios5

上周我下载了 Xcode 4.2,所以当我开始构建应用程序时,我尝试将 UITableView 添加到我的一个项目中(就像我开始开发以来所做的一样)但是 UITableView 不工作。我一直在寻找教程,但没有找到: 我如何在 Xcode 4.2 上为 IOS 5 创建一个 UITableView?

obs:我没有使用 Storyboard,只是 XIB 的!

最佳答案

在您的 .h 文件中,添加以下内容:

@interface YourClass: UIViewController <**UITableViewDataSource, UITableViewDelegate**>

右键单击(或按住 ctrl 键单击)并从您的 tableView 拖动到 File's Owner 两次。一次,选择“delegate”,一次选择“dataSource”。

然后,在您的 .m 文件中,您需要实现以下内容:

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

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

- (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];
    }

    [[cell textLabel] setText:yourText];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //do what you want to with the information at indexPath.row
}

这应该会让您获得一个可用的 tableView。

关于iphone - 我如何在 Xcode 4.2 上为 IOS 5 创建一个 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7910206/

相关文章:

c++ - 如何找到字节的排列或组合?

iphone - 构建失败,xcode 4.4中没有错误

ios - Xcode 中的 Firebase 身份验证和实时数据库 : How do I only show data relevant to ONE user not all?

objective-c - 仪器泄漏/怪异的内存泄漏

iphone - iphone如何判断当前年份是否闰年

c++ - 如何将矩阵列表从 Rcpp 返回到 R?

iphone - 初始化纵向和横向的 UIViewController

c++ - 矩阵的行、列和对角线之和

iphone - 在 iPhone 应用程序中设置货币

iphone - UIView的addSubview真的保留了view吗?