大佬教程收集整理的这篇文章主要介绍了objective-c – 在编辑模式下将UISearchBar与UITableView一起使用时,搜索结果不处于编辑模式,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么结果没有出现在编辑模式中?
编辑模式,不使用搜索栏:
提前致谢,
亚历克斯
这是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;
}
@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]; }
}
以上是大佬教程为你收集整理的objective-c – 在编辑模式下将UISearchBar与UITableView一起使用时,搜索结果不处于编辑模式全部内容,希望文章能够帮你解决objective-c – 在编辑模式下将UISearchBar与UITableView一起使用时,搜索结果不处于编辑模式所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。