在iOS上的搜索栏中输入时出现异常

时间:2014-09-17 16:37:45

标签: ios objective-c cocoa-touch

我接管了一些代码,因为另一个开发人员继续前进并且他的搜索栏出错了。我已经在其他线程上搜索过这方面的帮助,但似乎没有一个是我的错误。这是我的屏幕截图和代码。

http://imgur.com/gO6wuPb

2014-09-17 11:25:34.665 Moca [11388:60b] * 由于未捕获的异常终止应用' NSUnknownKeyException',原因:' [valueForUndefinedKey :]:此类不是键值itemName的键值编码兼容。'

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

if (tableView == self.searchDisplayController.searchResultsTableView) {
    return [searchResults count];

} else {
     return [[[BNRItemStore sharedStore] allItems] count];
}
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 71;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"UITableViewCell";
UITableViewCell *cell = (UITableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//there are two tableviews involved here - one is the main one, and one is associated with searchDisplayController
//self.tableView is set automatically between the main one and the search one.

// Configure the cell...
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


NSArray *items = [[BNRItemStore sharedStore] allItems];
BNRItem *item = nil;


if (tableView == self.searchDisplayController.searchResultsTableView) {
    item = [searchResults objectAtIndex:indexPath.row];
} else {
    item = items[indexPath.row];

}

if ([item.subcategory isEqual:@"Urgent"]) {
    cell.imageView.image=[UIImage imageNamed:@"Urgent.png"];
}
else if ([item.subcategory isEqual:@"Emergency"]) {
    cell.imageView.image=[UIImage imageNamed:@"Emergency.png"];
}
else if ([item.subcategory isEqual:@"Standard"]) {
    cell.imageView.image=[UIImage imageNamed:@"Standard.png"];
}
else if ([item.subcategory isEqual:@"Normal"]) {
    cell.imageView.image=[UIImage imageNamed:@"Normal.png"];
}
else {
    cell.imageView.image=[UIImage imageNamed:@"Informational.png"];

}
cell.textLabel.text = item.changeOrder;
cell.detailTextLabel.text =item.title;
return cell;
}

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSArray *items = [[BNRItemStore sharedStore] allItems];
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"itemName contains[c] %@", searchText];
searchResults = [items filteredArrayUsingPredicate:resultPredicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
                           scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                  objectAtIndex:[self.searchDisplayController.searchBar
                                                 selectedScopeButtonIndex]]];

return YES;
}

编辑添加项目详细信息

#import <Foundation/Foundation.h>

@interface BDDetailedChange : NSObject


+ (instancetype)randomItem;

- (instancetype)initWithItemName:(NSString *)name
              valueInDollars:(NSString *)value
                serialNumber:(NSString *)sNumber;

@property (nonatomic, copy) NSString *itemName;
@property (nonatomic, copy) NSString *serialNumber;
@property (nonatomic, copy) NSString *valueInDollars;
@property (nonatomic, readonly, strong) NSDate *dateCreated;
@property (nonatomic, copy) NSString *subcategory; //Emergency
@property (nonatomic, copy) NSString *service; 
@property (nonatomic, copy) NSString *associatedCIs; 
@property (nonatomic, copy) NSString *environment;//    Production
@property (nonatomic, copy) NSString *approvalGroup;
@property (nonatomic, copy) NSString *initiator;
@property (nonatomic, copy) NSString *coordinator;
@property (nonatomic, copy) NSString *riskLevel;//  Low
@property (nonatomic, copy) NSString *performingGroup;
@property (nonatomic, copy) NSString *implementationPlan;
@property (nonatomic, copy) NSString *validationPlan;
@property (nonatomic, copy) NSString *recoveryScope;


@end

BNR项目.h

@interface BNRItem : NSObject

{

 NSString *_approverEid;
 NSString *_assignmentGroup;
 NSString *_changeOrder;
 NSString *_subcategory; //Emergency
 NSString *_title; //title
}

- (void)setApproverEid: ( NSString *)aEid;
- (NSString*)approverEid;

- (void)setAssignmentGroup: ( NSString *)aGrp;
- (NSString*)assignmentGroup;

- (void)setChangeOrder: ( NSString *)co;
- (NSString*)changeOrder;

- (void)setSubcategory: ( NSString *)sub;
- (NSString*)subcategory;

- (void)setTitle: ( NSString *)title;
- (NSString*)title;

@end

BNRItem.m

#import "BNRItem.h"


@implementation BNRItem

- (void)setApproverEid:(NSString *)aEid
{
_approverEid = aEid;

}

- (void)setAssignmentGroup: ( NSString *)aGrp
{
_assignmentGroup = aGrp;
}

- (void)setChangeOrder: ( NSString *)co
{
    _changeOrder=co;
}

- (void)setSubcategory: ( NSString *)sub
{
_subcategory= sub;
}

- (void)setTitle: ( NSString *)title
{
_title = title;
}


- (NSString*)approverEid
{
return _approverEid;
}

- (NSString*)assignmentGroup
{
return _assignmentGroup;
}


- (NSString*)changeOrder
{
return _changeOrder;
}


- (NSString*)subcategory
{
return _subcategory;
}


- (NSString*)title
{
return _title;
}

@end

0 个答案:

没有答案