uisearchbar를 통해 스테이션을 선택할 수있는 설정 화면을 만들고 있습니다. 나는 섹션으로 된 테이블 뷰를 가지고있다. 헤더의 첫 번째 문자가 헤더이고 모든 스테이션은 첫 번째 문자로 분류된다. 여태까지는 그런대로 잘됐다. 섹션 당 2 개의 NSMutableArray를 보유하고 있습니다. 하나는 필터링되지 않은 배열 (필터링하지 않을 때 사용하는 배열)이고 다른 하나는 내가 무엇을 검색 할 때입니다. (나는 술어를 통해 이것을한다). 키보드의 모든 키 누르기에서 [self.tableView reloadData]; 이 작동하지만 스크롤 뷰는 너무 오래 유지됩니다! 따라서 선택한 배열에 실제로 얼마나 많은 결과가 있는지 과거로 스크롤 할 수 있습니다. 존재하지 않는 객체를 얻으려고하기 때문에 충돌이 발생합니다.TableView가 제대로 다시로드되지 않습니다.
테이블 뷰가 배열의 개수를 세지 않는 것처럼 보입니까? 이 문제에 익숙한 사람이 있습니까? 여기
은 일부 코드입니다 : 당신은 지금이 문제를 해결했을 수도- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (self.searching) {
return [self.tableFilterd count];
} else {
return [self.tableData count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"Rows for section");
// Return the number of rows in the section.
if (self.searching) {
NSLog(@"Editing section: %i, count %i", section, [[self.tableFilterd objectAtIndex:section] count]);
return [[self.tableFilterd objectAtIndex:section] count];
} else {
NSLog(@"Not editing");
return [[self.tableData objectAtIndex:section] count];
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
SettingsHeaderCell *cell = [[[SettingsHeaderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HeaderCell"] autorelease];
cell.labelLetter.text = [[self.tableLetters objectAtIndex:section] capitalizedString];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 52;
}
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
SettingsCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[SettingsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (self.searching) {
StationObject *object = (StationObject *)[[self.tableFilterd objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
[cell setStationObject:object];
} else {
StationObject *object = (StationObject *)[[self.tableData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
[cell setStationObject:object];
}
return cell;
}
NSArray를 사용하여 tableView를 채 웁니다. 실제로 u를 추가하면 nsarray에서 항목을 한 번 추가하거나 제거 할 수 없습니다. 그래서 당신의 배열은 항상 같고 필터링되지 않습니다. 배열을 어떻게 든 업데이트하는 경우 nsmutablearray를 사용하십시오. –
아뇨, NSMutableArray입니다. –
필터링 된 배열을 채우는 위치에 코드를 게시 할 수 있습니까? –