Iphone 如何在Xcode 4.2上为IOS 5创建UITableView?
上周我下载了Xcode 4.2,所以当我开始构建应用程序时,我尝试将Iphone 如何在Xcode 4.2上为IOS 5创建UITableView?,iphone,c++,xcode,uitableview,ios5,Iphone,C++,Xcode,Uitableview,Ios5,上周我下载了Xcode 4.2,所以当我开始构建应用程序时,我尝试将UITableView添加到我的一个项目中(就像我开始开发以来一直做的那样),但是UITableView不起作用。我正在搜索教程,但没有找到任何教程: 如何在Xcode 4.2上为IOS 5创建UITableView obs:我不是在使用故事板,只是在使用XIB > P>你应该从项目模板“Mead Debug应用程序”开始,并查看在C++中创建自己代码的机制。 但在核心部分,创建UITableView需要两步: 初始化视图 将
UITableView
添加到我的一个项目中(就像我开始开发以来一直做的那样),但是UITableView
不起作用。我正在搜索教程,但没有找到任何教程:
如何在Xcode 4.2上为IOS 5创建UITableView
obs:我不是在使用故事板,只是在使用XIB > P>你应该从项目模板“Mead Debug应用程序”开始,并查看在C++中创建自己代码的机制。 但在核心部分,创建UITableView需要两步:
- 初始化视图
- 将其插入其委托/数据源
此外,这可能对您有所帮助:在.h文件中,添加以下内容:
@interface YourClass: UIViewController <**UITableViewDataSource, UITableViewDelegate**>
- (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。“UITableView不工作”。。。。什么不起作用?首先,当我将UITableView添加到我的xib和build中时,我尝试滚动tableview,但什么都没有发生!你能分享一些代码吗?具体来说,tableview数据源和委托回调?仅在视图上删除tableview是不够的。您必须设置datasource&delegate并实现回调方法。您是否在ios5之前完成过tableView编码?我建议大家学习一下UITableView教程——很多都是在网上学习的。顺便说一句,它在ios5上运行良好。有一个较长的UITableView编程指南(附图片)