tableview에서 검색을 수행하려고합니다. 그러나이 테이블 뷰에서는 사용자 정의 Tableview Cell을 사용합니다. 그래서 데이터 부분입니다. 보기에서 범주를 선택합니다. 그런 다음 다음보기에서이 범주 내의 모든 제품을 가져옵니다. 나는이 모든 과정을 구현 한 tutorial을 따랐다.사용자 지정 tableviewCell 검색
이것은 제품을 가져 오는 내 기능입니다.
-(void) fillArrayProducts:(NSString *)cat{
NSMutableString *postString = [NSMutableString stringWithString:kGETProducts];
[postString appendString:[NSString stringWithFormat:@"?%@=%@",@"Pro_cat",cat]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request= [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:postString]];
NSError *error;
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
arrayProducts = [[NSMutableArray alloc] init];
copyArrayProducts = [[NSMutableArray alloc] init];
arrayProductNaam = [[NSMutableArray alloc] init];
for (int i=0; i<[json count]; i++) {
arrayProduct = [[NSMutableArray alloc] init];
[arrayProduct addObject:[json objectAtIndex:i]];
[arrayProducts addObject:arrayProduct];
[arrayProductNaam addObject:[[[arrayProducts valueForKey:@"Pro_naam"] objectAtIndex:i]objectAtIndex:0]];
[copyArrayProducts addObject:arrayProduct];
}
NSDictionary *productsDict = [NSDictionary dictionaryWithObject:arrayProductNaam forKey:@"Products"];
NSLog(@"%@",arrayProductNaam);
}
내가하는 일이 없습니다. 배열 'arrayProducts'이 배열에 배열을 'arrayProduct'에서 넣어. arrayProduct에서 Pro_id, Pro_naam, Pro_prijs를 찾을 수 있습니다. 하지만 Pro_naam 만 검색하고 싶습니다. 따라서 배열 (arrayProductNaam)에는 제품 이름 만 채 웁니다.
여기 내 검색을 수행하는 부분이 있습니다.
- (void) searchTableView {
NSString *searchText = searchbar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in arrayProductNaam)
{
NSArray *array = [dictionary objectForKey:@"Pro_naam"];
[searchArray addObjectsFromArray:array];
}
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyArrayProducts addObject:sTemp];
}
}
나는이 오류가 발생했다고 생각합니다. 22 :
2012-02-02 13
MamzelBestelling2 40.958 [23,727 : F803] - [__ NSCFString objectForKey :] : 22 : 40.959 MamzelBestelling2 [23,727 인식 선택기 인스턴스 0x6c34780 2012-02-02 13 보내 : 인해 캐치되지 않는 예외 'NSInvalidArgumentException'에 응용 프로그램을 종료 F803] *, 이유 : '- [__ NSCFString objectForKey :] : 인식 할 수없는 선택기 예를 0x6c34780로 전송'당신의 문자열 배열을 NSLog하는
for 루프에서 NSLog를 시도하면 아무 것도 인쇄되지 않습니다. 하지만 for 루프가 시작되기 직전에 어느 정도 나타납니다. – Steaphann
검색 텍스트를 인쇄 해 주시겠습니까? – Hiren
한 글자를 누를 때 immediatly 충돌이 발생합니다. 그러나이 메시지는 내 NSF 로그에도 인쇄됩니다. – Steaphann