如何在XOS 4.2上为IOS 5创建UITableView? [英] How can i create an UITableView on Xcode 4.2,for IOS 5?

查看:100
本文介绍了如何在XOS 4.2上为IOS 5创建UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上周我已经下载了Xcode 4.2,所以当我开始构建应用程序时,我试图将 UITableView 添加到我的一个项目中(正如我以前一样)自从我开始开发以来这样做但是 UITableView 无效。我正在寻找教程,但我没有找到任何教训:
如何在Xcode 4.2上为IOS 5创建一个UITableView?

Last week i have downloaded Xcode 4.2, so when i started building apps i've tried to add an UITableView to one of my projects (as normal as i have been doing since i began developing) but the UITableView isn't working. I've searching for tutorials but i didn't found any so: How can i create an UITableView on Xcode 4.2,for IOS 5?

obs:我没有在你的.h文件中使用storyBoard只是XIB的!

obs:I'm not using storyBoard just the XIB's!

推荐答案

,添加以下内容:

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

右键单击(或按住Ctrl键单击)并从tableView拖动到文件所有者两次。一次,选择delegate,然后选择dataSource。

right-click (or ctrl-click) and drag from your tableView to the File's Owner twice. Once, select "delegate", and once select "dataSource".

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

Then, in your .m file, you need to implement the following:

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

这应该可以让你找到一个工作表。

That should get you a working tableView.

这篇关于如何在XOS 4.2上为IOS 5创建UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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