我如何在Xcode 4.2上创建一个UITableView,用于IOS 5
How can i create an UITableView on Xcode 4.2,for IOS 5?
上周我下载了Xcode 4.2,所以当我开始构建应用程序时,我试图将UITableView
添加到我的一个项目中(就像我开始开发以来一直在做的那样正常),但UITableView
不工作。我一直在寻找教程,但我没有找到任何这样:我如何在Xcode 4.2上创建一个UITableView,用于IOS 5?
obs:我没有使用storyBoard只是XIB的!
在.h文件中添加以下内容:
@interface YourClass: UIViewController <**UITableViewDataSource, UITableViewDelegate**>
右键单击(或ctrl-click)并从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
您应该从项目模板"Master-Detail Application"开始,并查看在c++中创建自己的代码的机制。
但在核心,创建一个UITableView是两个步骤:
- 初始化视图
- 将其插入其委托/数据源
同样,这可能会帮助你:我可以用c++语言写Cocoa Touch[iPhone]应用程序吗
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 在c++中用vector填充一个简单的动态数组
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 预处理器:插入结构名称中的前一个行号
- 我在c++代码中生成了一个运行时#3异常
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 从链接列表c++中删除一个项目
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '