gpt4 book ai didi

ios - 当第一个字母按下 UISearchBar 字段时,UISearchbar 消失,iOS7

转载 作者:行者123 更新时间:2023-12-04 14:51:09 30 4
gpt4 key购买 nike

这里是我在view controller.h中的代码

#import "AppDelegate.h"

@interface SearchRsultsFanSideViewController : UIViewController<UISearchBarDelegate,UISearchDisplayDelegate>
{
}
@property (strong, nonatomic) IBOutlet UISearchBar *searchData;


@property (strong, nonatomic) UISearchDisplayController *controller;

在viewcontroller.m中

- (void)viewDidLoad
{
[super viewDidLoad];
searchResults=[[NSArray alloc]init];
self.controller = [[UISearchDisplayController alloc]initWithSearchBar:searchData contentsController:self];
self.controller.searchResultsDataSource = self;
self.controller.searchResultsDelegate = self;
}

UIsearchbar 的委托(delegate)方法

#pragma Mark - SearchBar Delegate

- (void)filterData
{

searchResults = nil;

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [cd] %@", searchData.text];
NSArray *arrayaaa=[finalArray copy];
NSLog(@"The result Datas==%@",arrayaaa);
searchResults = [[arrayaaa filteredArrayUsingPredicate:predicate] mutableCopy];


}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

[self.searchDisplayController setActive:YES];

[self filterData];

}

最佳答案

试试这个

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller{
[controller.searchBar setFrame:CGRectMake(44, 0, 320 - 44, 43)];
[self.searchDisplayController.searchResultsTableView setDelegate:self];
}

关于ios - 当第一个字母按下 UISearchBar 字段时,UISearchbar 消失,iOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20991246/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com