我正在 iPhone 中完成 AutoCompleteTextView 的概念,类似于我们在进行 safari 时发现的。我是在 UITableView 的帮助下完成的。但是我收到错误“程序收到信号 SIGABRT”无法理解我哪里出错了..?
我的数组看起来像这样:
(
{
Name = "John";
},
{
Name = "Williams ";
},
{
Name = "Michael ";
},
{
Name = "Hillary ";
},
{
Name = "Jennifer ";
},
)
所以我必须在 tableView 的单元格中获取 Name 的值。
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
[autocompleteUrls removeAllObjects];
for(int i=0;i<[arr2 count];i++)
{
for(NSString *curString in [[arr2 objectAtIndex:i] valueForKey:@"Name"]) //error :Program recieved signal SIGABRT
{
NSRange substringRange = [curString rangeOfString:substring];
if (substringRange.location == 0)
{
[autocompleteUrls addObject:curString];
}
}
}
[autocompleteTableView reloadData];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if( textField == txtcity)
{
[txtcity resignFirstResponder];
autocompleteTableView.hidden = NO;
NSString *substring = [NSString stringWithString:textField.text];
substring = [substring stringByReplacingCharactersInRange:range withString:string];
[self searchAutocompleteEntriesWithSubstring:substring];
return YES;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
return autocompleteUrls.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];
}
cell.textLabel.text = [autocompleteUrls objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
txtcity.text = selectedCell.textLabel.text;
}
我在这一行遇到错误:for(NSString *curString in [[arr2 objectAtIndex:i] valueForKey:@"Name"])
我哪里错了..?任何帮助,将不胜感激..