ios – UISeachBar和委托方法

ios – UISeachBar和委托方法,第1张

概述我想在一个用NSMutableArray填充的UITableView上完成一个搜索栏.问题是搜索栏委托方法显然不起作用.当我在搜索栏中输入内容时,我得不到答案,即使NSLog(@“test”)也没有触发,这让我发疯.如果我能得到任何帮助请. (新秀ObjC级别^^) 这是我的代码(减去所有解析xml部分): (.H) #import <UIKit/UIKit.h>#import <Foundat 我想在一个用NSMutableArray填充的UItableVIEw上完成一个搜索栏.问题是搜索栏委托方法显然不起作用.当我在搜索栏中输入内容时,我得不到答案,即使NSLog(@“test”)也没有触发,这让我发疯.如果我能得到任何帮助请. (新秀ObjC级别^^)

这是我的代码(减去所有解析xml部分):
(.H)

#import <UIKit/UIKit.h>#import <Foundation/Foundation.h>@interface MetamorphVIEwController : UItableVIEwController <UISearchbarDelegate,UISearchdisplayDelegate>{    IBOutlet UItableVIEw * newstable;    UISearchbar *searchbar;    UISearchdisplayController *searchdisplayController;    UIActivityIndicatorVIEw * activityIndicator;    CGSize cellSize;    NSXMLParser * RSSParser;    NSMutableArray * storIEs;    NSArray * newStorIEs;    NSMutableArray *filteredStorIEs;    Nsstring *dataType;    Nsstring *IDname;    BOol *uploaded;    BOol isFiltered;    NSMutableDictionary * item;    Nsstring * currentElement;    NSMutableString * currentTitle,* currentDate,* currentSummary,* currentlink,* currentModule,*currentOwner,*currentOwnername;}- (voID)parseXMLfileAtURL:(Nsstring *)URL typeOfModule:(Nsstring *)typeOfData;@end

(.M)

- (voID)vIEwDIDLoad {    self.navigationItem.rightbarbuttonItem = self.editbuttonItem;    searchbar = [[UISearchbar alloc] initWithFrame:CGRectMake(0,70,320,44)];    [searchbar setShowsScopebar:YES];    [searchbar setScopebuttonTitles:[[NSArray alloc] initWithObjects:@"OBJ",@"C",nil]];    searchdisplayController = [[UISearchdisplayController alloc] initWithSearchbar:searchbar contentsController:self];    searchdisplayController.delegate = self;    searchdisplayController.searchResultsDataSource = self;    [searchdisplayController setSearchResultsDelegate:self];    self.tableVIEw.tableheaderVIEw = searchbar;    [self.tableVIEw reloadData];    self.tableVIEw.scrollEnabled = YES;}-(voID)searchbar:(UISearchbar *)searchbar textDIDChange:(Nsstring *)searchText{    NSLog(@"test");    //nspredicate *filterPredicate = [nspredicate predicateWithFormat:@"SELF beginswith[c] %@",searchbar];     //newStorIEs = [storIEs filteredArrayUsingPredicate:filterPredicate];    //NSLog(@"newStorIEs %@",newStorIEs);}
解决方法 您尚未将searchset设置为searchbar对象.在那之后:

[searchbar setShowsScopebar:YES];

加:

searchbar.delegate = self;

不要忘记添加< UISearchbarDelegate>协议.

总结

以上是内存溢出为你收集整理的ios – UISeachBar和委托方法全部内容,希望文章能够帮你解决ios – UISeachBar和委托方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1054773.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存