上周我已经下载了Xcode 4.2,所以当我开始构建应用程序时,我试图将UITableView
添加到我的一个项目中(正如我开始开发以来一样正常),但UITableView
不起作用。我正在寻找教程,但我没有找到任何如此: 我如何创建一个UITableView Xcode 4.2,IOS 5?如何在iOS 5上的Xcode 4.2上创建UITableView?
obs:我没有使用storyBoard只是XIB的!
上周我已经下载了Xcode 4.2,所以当我开始构建应用程序时,我试图将UITableView
添加到我的一个项目中(正如我开始开发以来一样正常),但UITableView
不起作用。我正在寻找教程,但我没有找到任何如此: 我如何创建一个UITableView Xcode 4.2,IOS 5?如何在iOS 5上的Xcode 4.2上创建UITableView?
obs:我没有使用storyBoard只是XIB的!
在您的.h文件中,添加以下内容:
@interface YourClass: UIViewController <**UITableViewDataSource, UITableViewDelegate**>
右键单击(或按住Ctrl并单击)并从您的tableView拖到文件所有者两次。一旦选择“委托”,并选择“数据源”。
然后,在你的.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。
您应该从项目模板“主 - 细节应用程序”开始,查看使用C++创建自己的代码的机制。
但是为核心,打造一个UITableView是一个两步:
也,这可以帮助你:Can i write Cocoa Touch[iPhone] applications in C++ language
“UITableView无法正常工作”.... *什么是不工作? –
首先,当我只是将UITableView添加到我的xib并构建时,我尝试滚动tableview而没有任何反应! – Mateus
你能分享一些代码吗?具体来说,tableview数据源和委托回调? – bryanmac