开发者

UITableView Search Display Cell Error

- (void)view开发者_如何学GoDidLoad {
   [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 order with the searched names

before search:

UITableView Search Display Cell Error

searching for newark:

UITableView Search Display Cell Error

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


One way would be to use a dictionary. The keys could be names and values could be the numbers.

NSDictionary *amounts = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:5], @"Ohio", [NSNumber numberWithInt:100], @"Newark", etc.., nil];

To get a number mapped to Newark:

NSNumber *numberNewark = [amounts objectForKey:@"Newark"];

An NSNumber is just a wrapper for a primitive and can be replaced where you use NSString, it writes out the number it wraps. Example NSLog(@"%@", numberNewark); will write '100' to console.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜