为什么结果没有出现在编辑模式中?
编辑模式,不使用搜索栏:
在编辑模式下搜索会生成不处于编辑模式且未设置样式的结果:
提前致谢,
亚历克斯
这是shouldReloadtableForSearchString方法:
- (BOol)searchdisplayController:(UISearchdisplayController *)controller shouldReloadtableForSearchString:(Nsstring *)searchString {nspredicate *predicate = nil;if ([searchString length]){ NSArray* filteredTags = nil; if ([searchString length] < 3) { // Check for Tags starting with 1 or 2 characters. filteredTags = [[tagResultsController fetchedobjects] filteredArrayUsingPredicate:[nspredicate predicateWithBlock:^BOol(TagEntity* te,NSDictionary *bindings) { if ([[[te.name lowercaseString] substringToIndex:[searchString length]] isEqualToString:[searchString lowercaseString]]) return YES; return NO; }]]; } else { // Check for Tags with 3 or more consecutive characters anywhere in name filteredTags = [[tagResultsController fetchedobjects] filteredArrayUsingPredicate:[nspredicate predicateWithBlock:^BOol(TagEntity* te,NSDictionary *bindings) { if ([[te.name lowercaseString] rangeOfString:[searchString lowercaseString]].location != NSNotFound) return YES; return NO; }]]; } // OR ANY(self.Tags) in %@ predicate = [nspredicate predicateWithFormat: @"ANY(self.songLists) in %@ AND (name contains[cd] %@ OR artist_name contains[cd] %@ OR number = %@ OR ANY(tag_entitIEs) in %@)",currentSongList.songs,searchString,filteredTags]; [self.fetchedResultsController.fetchRequest setPredicate:predicate]; NSError *error = nil; if (![[self fetchedResultsController] performFetch:&error]) { NSLog(@"Unresolved error %@,%@",error,[error userInfo]); abort(); } // Return YES to cause the search result table vIEw to be reloaded.}return YES;
}
这是我的核心数据表视图来自.h文件的标题:
@interface SongListTVC : CoreDatatableVIEwController<UISearchbarDelegate,UISearchdisplayDelegate,UIPickerVIEwDataSource,UIPickerVIEwDelegate,UIActionSheetDelegate,AddSongTVCDelegate,ListSelectorDelegate>
我知道它正在使用我的表视图控制器,因为cellForRowAtIndexPath和dIDSelectRowAtIndexPath都在触发.我可以调试内部,并在表视图上将isEditing设置为YES.但是表格视图并没有反映它正确的编辑模式样式.
这是在搜索框中键入字母后立即触发的cellForRowAtIndexPath.
- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {Nsstring *IDentifIEr = @"SongCell";UItableVIEwCell *cell = [self.tableVIEw dequeueReusableCellWithIDentifIEr:IDentifIEr];Song* song = [self.fetchedResultsController objectAtIndexPath:indexPath]; UILabel* artistLabel = (UILabel*)[cell vIEwWithTag:ARTIST_name_TAG];UILabel* songLabel = (UILabel*)[cell vIEwWithTag:SONG_name_TAG];UILabel* keyLabel = (UILabel*)[cell vIEwWithTag:KEY_TAG];UILabel* numberLabel = (UILabel*)[cell vIEwWithTag:NUMBER_TAG];//artistLabel.Font = [UIFont systemFontOfSize:17];[artistLabel setText: song.artist_name];[songLabel setText: song.name];//[songLabel setFont:[UIFont systemFontOfSize:16]];[keyLabel setText: song.key];[numberLabel setText: [Nsstring stringWithFormat:@"%@",song.number]];UIVIEw *backVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,320,61)];UIVIEw *selectedBackVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,61)];CAGradIEntLayer *backGradIEnt = [[CAGradIEntLayer alloc] init];backGradIEnt.frame = cell.layer.bounds;CAGradIEntLayer *selectedGradIEnt = [[CAGradIEntLayer alloc] init];selectedGradIEnt.frame = cell.layer.bounds;if (song.status == [NSNumber numberWithUnsignedInt: 1]){ [backGradIEnt setcolors:[NSArray arrayWithObjects: (ID)[[UIcolor colorWithRed:240.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f Alpha:1.0f] CGcolor],(ID)[[UIcolor colorWithRed:1 green:1 blue:1 Alpha:1.0f] CGcolor],nil]];}else if (song.status == [NSNumber numberWithUnsignedInt: 2]){ [backGradIEnt setcolors:[NSArray arrayWithObjects: (ID)[[UIcolor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:200.0f/255.0f Alpha:1.0f] CGcolor],nil]];}else if (song.status == [NSNumber numberWithUnsignedInt: 3]){ [backGradIEnt setcolors:[NSArray arrayWithObjects: (ID)[[UIcolor colorWithRed:200.0f/255.0f green:240.0f/255.0f blue:200.0f/255.0f Alpha:1.0f] CGcolor],nil]];}[selectedGradIEnt setcolors:[NSArray arrayWithObjects: (ID)[[UIcolor colorWithRed:255.0f/255.0f green:160.0f/255.0f blue:60.0f/255.0f Alpha:1.0f] CGcolor],(ID)[[UIcolor colorWithRed:1 green:1 blue:1 Alpha:0.7f] CGcolor],nil]];if (![self.tableVIEw isEditing] ){ cell.backgroundVIEw = backVIEw; [cell.backgroundVIEw.layer insertSublayer:backGradIEnt atIndex:1]; cell.selectedBackgroundVIEw = selectedBackVIEw; [cell.selectedBackgroundVIEw.layer insertSublayer:selectedGradIEnt atIndex:1];}else{ //cell.backgroundVIEw = backVIEw; //[cell.backgroundVIEw.layer insertSublayer:backGradIEnt atIndex:1]; cell.selectedBackgroundVIEw = backVIEw; [cell.selectedBackgroundVIEw.layer insertSublayer:backGradIEnt atIndex:1];}for (NSIndexPath* ip in selectedindexes){ [self.tableVIEw selectRowAtIndexPath:ip animated:YES scrollposition:UItableVIEwScrollpositionNone];}[sortOrderPicker reloadAllComponents];[self sendPickerDownAnimated:NO];return cell;
}
我使用分段控件内的按钮来切换编辑ON / OFF:
- (IBAction)segmentChanged:(ID)sender{UISegmentedControl* sg = (UISegmentedControl*)sender;if (sg.selectedSegmentIndex == 0){ // Edit if (![self.tableVIEw isEditing]) { [self.tableVIEw setEditing:YES animated:YES]; [self.navigationController setToolbarHIDden:NO animated:YES]; } else { [self.tableVIEw setEditing:NO animated:YES]; [self.navigationController setToolbarHIDden:YES animated:YES]; selectedindexes = nil; } [self.tableVIEw reloadData];}else{ // Sort if (pickerShown) [self sendPickerDownAnimated:YES]; else [self bringPickerUpAnimated:YES];}
}
解决方法 问题在于UISearchdisplayController会自动为您做很多事情.它创建自己的表视图以显示搜索结果,并管理该表视图.您可以将自己设置为该表视图的数据源和委托,并且默认情况下会自动为您完成,但它不是您的表视图而您无法控制它.如果你想要一个更大的手指定这是什么表视图,你需要设置搜索显示控制器的searchResultstableVIEw;或者你可以随着事情的进行获得它的引用(例如通过UISearchdisplayController自己的委托方法).但即便如此,您也不会成为管理结果表视图的UItableVIEwController;这完全是内部的UISearchdisplayController.如果您不喜欢这样,一个简单的解决方案是:不要使用UISearchdisplayController – 想想另一个接口. 总结以上是内存溢出为你收集整理的objective-c – 在编辑模式下将UISearchBar与UITableView一起使用时,搜索结果不处于编辑模式全部内容,希望文章能够帮你解决objective-c – 在编辑模式下将UISearchBar与UITableView一起使用时,搜索结果不处于编辑模式所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)