gpt4 book ai didi

ios - 后退后 UISearchBar 错误

转载 作者:行者123 更新时间:2023-11-29 03:15:02 24 4
gpt4 key购买 nike

我创建了一个 UISearchBar,它在我第一次进入 viewController 时起作用,但是当我通过它进入下一个 viewcontroller 时。 UITableView 并按回并尝试再次搜索我收到以下错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<phraseObject 0xa72d8c0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.'

代码如下:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"language"]) {
thename = attributeDict[@"name"];
theimage = attributeDict[@"image"];
theId = attributeDict[@"id"];

object = [finalObject new];
theObject = [countryObject new];

object.name = thename;
object.image = theimage;
object.soId = theId;

theObject.name = thename;
theObject.image = theimage;
theObject.soId = theId;

[finalArray addObject:object];
[finalArray2 addObject:theObject];

}
}

-(void) searchThroughdata {

self.filteredArray = nil;

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains [c] %@",self.searchBar.text];
self.filteredArray = [[finalArray filteredArrayUsingPredicate:predicate] mutableCopy];

}

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
[self searchThroughdata];
}


- (void)viewDidLoad
{
[super viewDidLoad];

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
height = 30.0;
searchBar.barTintColor = [UIColor clearColor];

self.tableViewData.sectionIndexTrackingBackgroundColor = [UIColor clearColor]; // background color while the index view is being touched
if ([self.tableViewData respondsToSelector:@selector(sectionIndexBackgroundColor)]) {
self.tableViewData.sectionIndexBackgroundColor = [UIColor clearColor];
}
tableViewData.backgroundColor = [UIColor clearColor];
tableViewData.opaque = NO;
tableViewData.backgroundView = nil;

NSString* path = [[NSBundle mainBundle] pathForResource: @"lists" ofType: @"xml"];
NSData* data = [NSData dataWithContentsOfFile: path];


rows = [[NSMutableArray alloc] init];
finalArray = [[NSMutableArray alloc] init];
finalArray2 = [[NSMutableArray alloc] init];

NSXMLParser* parser = [[NSXMLParser alloc] initWithData: data];

[parser setDelegate:self];
[parser parse];

}

最佳答案

问题在:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains [c] %@",self.searchBar.text];

编译器无法找到 SELF.name

你在哪里搜索?对象键的名称是什么?

关于ios - 后退后 UISearchBar 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21796630/

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