我猜你已经来自网络开发?我也发现很难这样做,但它是最好的方式。 IT可能是可能的 - 但如果你习惯了这样做,它会更好。
基本上在.h文件中定义一个NSArray(因此整个脚本都可以使用它)。
然后在init函数:
// set the array
myArray = [NSArray arrayWithObjects:@"One",@"Two",@"Threee",nil];
[myArray retain];
则表视图的委托方法:
// set numebr of rows
- (CGFloat)tableView:(UITableView *)tableView numberOfRowsForSection:(NSUInteger)section {
return [myArray count];
}
// set the cell titleLabel value
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// set the cell - I can't remember the exact code then do:
cell.textLabel.text = [myArray objectAtIndex:[indexPath row]];
}
// similarly
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%@",[myArray objectAtIndex:[indexPath row]];
}
(免责声明:这些只是从我的头顶,我没有检查确切的方法 - 他们可能在某种程度上是错误的 - 但函数内的代码是你真正想要的。)
当你开始使用它时,你会看到它比“隐藏“表中的某个ID。为了从数据库中获得东西,我建议将它们全部添加到字典或数组中或类似的内容中,并且在初始化类时执行此操作,但是如果您确实想动态执行此操作,那么假装您的“隐藏”ID只是数组的索引。所以id#1位于数组中的索引1处。 :)
非常感谢你,我已经按照你的指示和它就像你说我来自网络的发展,发现它有点跑:-)奇怪.... – Cris 2010-09-28 10:07:32
是的,但很快你会意识到,如果网络以iphone的方式工作,世界将是一个更好的地方! :p哈哈 – 2010-09-28 11:04:35