2011-03-27 66 views
0
- (void)viewDidLoad { 
    [super viewDidLoad]; 

definedNames = [[NSArray alloc] initWithObjects:@"Ohio", @"Newark", @"Steve", @"Coffee", nil]; 

definedAmounts = [[NSArray alloc] initWithObjects:@"5", @"100", @"1", @"72", nil]; 

} 

例如。因此,数字与它匹配的名字去,但是当我搜索它与搜索到的名字UITableView搜索显示的单元格错误

搜索之前提出的数字仍然按照这个顺序: http://img855.imageshack.us/i/screenshot20110327at302.png

搜索纽瓦克: http://img849.imageshack.us/i/screenshot20110327at303.png

纽瓦克应保持100的价值。有人可以解释如何对我做这个请吗?我会很感激。我也有超过1000个条目和值显示在自定义单元格中。

感谢

+0

如何让索引数组显示您的信息? – klefevre 2011-03-27 21:53:51

+0

我不会分开这样的数据,为什么不只是一个数组与数组?例如,'self.stuff = [[NSArray alloc] initWithObjects:[NSArray arrayWithObjects:@“Ohio”,@“5”,nil],[NSArray arrayWithObjects:@“Newark”,@“100”,nil],nil ]'?然后设置你的tableview,你可以使用'[[stuff objectAtIndex:row] objectAtIndex:0];'作为名字,'[[stuff objectAtIndex:row] objectAtIndex:1];'为数字。带数组的 – 2011-03-27 21:58:25

+0

数组。超过1000我将如何把这些放入tableview? – 2011-03-27 22:02:06

回答

0

如果我是你,我就不会,如果你有“1000”像你说的做出正确的在运行时你的所有数据。我会做一个plist看起来是这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<array> 
    <array> 
     <string>Ohio</string> 
     <string>5</string> 
    </array> 
    <array> 
     <string>Newark</string> 
     <string>100</string> 
    </array> 
</array> 
</plist> 

,并保存为cities.plist,例如。

在你的初始化代码

然后,抢的plist与它初始化数组:

NSUInteger row = [indexPath row]; 
NSString *city = [[cityData objectAtIndex:row] objectAtIndex:0]; //use index 1 if you want number 
cell.textLabel.text = city; 
return cell; 

品牌:

NSString *citiesPath = [[NSBundle mainBundle] 
          pathForResource:@"cities" 
          ofType:@"plist"]; 
self.definedCities = [[NSMutableArray alloc] initWithContentsOfFile:citiesPath]; 

然后在cellForRowAtIndexPath,你可以通过这样设置你的根本在我看来,这简单得多。

+0

我得到那个现在的工作 但这是我的新问题,现在崩溃在这里,因为我还没有指定哪寻找。我会怎么做? 为(在[自cityNames]的NSString * currentString) \t \t { \t \t \t如果([currentString rangeOfString:SEARCHTERM选项:NSCaseInsensitiveSearch]!.location = NSNotFound) – 2011-03-27 22:23:48

+0

@Sean:可能要问,在一个不同的问题。 :) – 2011-03-27 23:37:25

相关问题