2011-03-27 27 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

相關問題