开发者

UITableView Search Displayed Cell Error

- (void)viewDidLoad {
   [super viewDidLoad];

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

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

}

That for example. So the numbers go with the name it matches but when i search it puts the numbers still in that ord开发者_运维技巧er with the searched names

before search: http://img855.imageshack.us/i/screenshot20110327at302.png

searching for newark: http://img849.imageshack.us/i/screenshot20110327at303.png

Newark should stay with the value 100. Can someone explain how to do this to me please? i would appreciate it. also i have over 1000 entries and the values are shown in a custom cell.

thanks


If I were you, I wouldn't make all your data right at runtime if you have "1000" like you said. I'd make a plist that looks something like this:

<?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>

And save it as cities.plist, for example.

Then in your initializing code, grab the plist and initialize your array with it:

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

Then in cellForRowAtIndexPath, you can set up your cell simply by doing this:

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

Makes it much simpler in my opinion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜