这是我的.h文件。在这个文件中我声明我想用于过滤器的searchresult和mail数组的数组是arrfullname。
DisplayAppointmentViewController.h
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [arrsearchresult count];
} else {
return [arrfullname count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
AppoinmentTableViewCell *cell = (AppoinmentTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AppoinmentTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
if (tableView == self.searchDisplayController.searchResultsTableView)
{
arrfullname = [arrsearchresult objectAtIndex:indexPath.row];
cell.lblFullname.text = [arrsearchresult objectAtIndex:indexPath.row];
cell.lblDate.text = [arrsearchresult objectAtIndex:indexPath.row];
cell.lblTime.text = [arrsearchresult objectAtIndex:indexPath.row];
}
cell.btnCall.tag = indexPath.row;
cell.btnMail.tag = indexPath.row;
cell.btnSms.tag = indexPath.row;
cell.btnCreatePlan.tag = indexPath.row;
cell.btnAppointment.tag = indexPath.row;
cell.btnStatus.tag=indexPath.row;
}
cell.clipsToBounds = YES;
if ([strCheckVC isEqualToString:@"OpenLead"])
{
cell.lblFullname.text = [arrfullname objectAtIndex:indexPath.row];
[self databaseOpen];
NSString *query_user=[ NSString stringWithFormat:@"Select * from lead_status where row_lead_id = %@ and lead_followup_datetime != ' ' order by rowid desc limit 1",[arrRowid objectAtIndex:indexPath.row]];
NSArray *rowids = [[NSArray alloc]init];
rowids =[[database executeQuery:query_user]mutableCopy];
NSLog(@"%@",rowids);
[database close];
if (rowids.count > 0 )
{
NSString *dateString = [[rowids valueForKey:@"lead_followup_datetime"]objectAtIndex:0];
NSArray *components = [dateString componentsSeparatedByString:@" "];
NSString *date = components[0];
NSString *time = components[1];
// date convert
NSString *dateStr = [NSString stringWithFormat:@"%@",date];
NSString *timestr = [NSString stringWithFormat:@"%@",time];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm:ss"];
NSDate *date11 = [dateFormat dateFromString:timestr];
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"hh:mm a"];
NSString *depResult = [df stringFromDate:date11];
cell.lblTime.text = depResult;
dateStr = [NSString stringWithFormat:@"%@",date];
// Convert string to date object
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-mm-dd"];
NSDate *viewdt = [dateFormat dateFromString:dateStr];
//date11 = [dateFormat dateFromString:dateStr];
NSLog(@"%@",date);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date22 = [dateFormatter dateFromString:dateStr];
[dateFormatter setDateFormat:@"dd MMM yyyy"];
NSString *dateWithNewFormat = [dateFormatter stringFromDate:date22];
NSLog(@"dateWithNewFormat: %@", dateWithNewFormat);
// df = [[NSDateFormatter alloc]init];
// [df setDateFormat:@"dd MMM yyyy"];
// depResult = [df stringFromDate:viewdt];
//
cell.lblDate.text = dateWithNewFormat;
}
else
{
// date convert
NSString *dateStr = [NSString stringWithFormat:@"%@",[appointmenttime objectAtIndex:indexPath.row]];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];
NSLog(@"%@",date);
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"hh:mm a"];
NSString *depResult = [df stringFromDate:date];
cell.lblTime.text = depResult;
dateStr = [NSString stringWithFormat:@"%@",[arrappointment_date objectAtIndex:indexPath.row]];
// Convert string to date object
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-mm-dd"];
date = [dateFormat dateFromString:dateStr];
NSLog(@"%@",date);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date22 = [dateFormatter dateFromString:dateStr];
[dateFormatter setDateFormat:@"dd MMM yyyy"];
NSString *dateWithNewFormat = [dateFormatter stringFromDate:date22];
NSLog(@"dateWithNewFormat: %@", dateWithNewFormat);
// df = [[NSDateFormatter alloc]init];
// [df setDateFormat:@"dd MMM yyyy"];
// depResult = [df stringFromDate:date];
//
cell.lblDate.text = dateWithNewFormat;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([[arremail objectAtIndex:indexPath.row] isEqual:[NSNull null]] || [[arremail objectAtIndex:indexPath.row] isEqualToString:@"<null>"] || [[arremail objectAtIndex:indexPath.row] isEqualToString:@""] )
{
cell.btnMail.hidden = NO;
}
NSUInteger hours_passed = [[arrhours_passed objectAtIndex:indexPath.row] integerValue];
if (hours_passed <= 72)
{
cell.colorView.backgroundColor = [UIColor whiteColor];
}
else if (hours_passed <= 144)
{
cell.colorView.backgroundColor = [UIColor colorWithRed:219.0/255.0 green:157.0/255.0 blue:157.0/255.0 alpha:1.0];
cell.lblDate.textColor = [UIColor whiteColor];
cell.lblTime.textColor = [UIColor whiteColor];
cell.lblFullname.textColor = [UIColor whiteColor];
}
else if (hours_passed <= 216)
{
cell.colorView.backgroundColor = [UIColor colorWithRed:202.0/255.0 green:114.0/255.0 blue:114.0/255.0 alpha:1.0];
cell.lblDate.textColor = [UIColor whiteColor];
cell.lblTime.textColor = [UIColor whiteColor];
cell.lblFullname.textColor = [UIColor whiteColor];
}
else if (hours_passed <= 288)
{
cell.colorView.backgroundColor = [UIColor colorWithRed:189.0/255.0 green:78.0/255.0 blue:78.0/255.0 alpha:1.0];
cell.lblDate.textColor = [UIColor whiteColor];
cell.lblTime.textColor = [UIColor whiteColor];
cell.lblFullname.textColor = [UIColor whiteColor];
}
[self databaseOpen];
NSString *str = [NSString stringWithFormat:@"Select * from lead_followup where rowid=%@",[arrRowid objectAtIndex:indexPath.row]];
NSMutableArray *arr = [[NSMutableArray alloc]init];
arr = [[database executeQuery:str]mutableCopy];
NSLog(@"arr data %@",arr);
[database close];
NSString *strsms;
if (arr.count != 0)
{
strsms = [NSString stringWithFormat:@"%@",[[arr valueForKey:@"followed_by_sms"]objectAtIndex:0]];
if ([strsms isEqualToString:@"0"])
{
if (hours_passed <= 72)
{
[cell.btnSms setImage:[UIImage imageNamed:@"Chatgray"] forState:UIControlStateNormal];
}
else if (hours_passed > 72)
{
//white
[cell.btnSms setImage:[UIImage imageNamed:@"chatwhite"] forState:UIControlStateNormal];
}
}
/*else
{
// green icon
[cell.btnSms setImage:[UIImage imageNamed:@"Chatgreen"] forState:UIControlStateNormal];
}*/
NSString *strCall = [NSString stringWithFormat:@"%@",[[arr valueForKey:@"followed_by_call"]objectAtIndex:0]];
NSLog(@"%@",strCall);
if ([strCall isEqualToString:@"0"])
{
if (hours_passed <= 72)
{
//blackCallGray
[cell.btnCall setImage:[UIImage imageNamed:@"CallGray"] forState:UIControlStateNormal];
}
else if (hours_passed > 72)
{
[cell.btnCall setImage:[UIImage imageNamed:@"CallWhite"] forState:UIControlStateNormal];
}
}
else
{
[cell.btnCall setImage:[UIImage imageNamed:@"CallGreen"] forState:UIControlStateNormal];
// green icon
}
NSString *strmail = [NSString stringWithFormat:@"%@",[[arr valueForKey:@"followed_by_mail"]objectAtIndex:0]];
NSLog(@"%@",strmail);
if ([strmail isEqualToString:@"0"])
{
if (hours_passed <= 72)
{
[cell.btnMail setImage:[UIImage imageNamed:@"Mailgray"] forState:UIControlStateNormal];
}
else if (hours_passed > 72)
{
[cell.btnMail setImage:[UIImage imageNamed:@"MailWhite"] forState:UIControlStateNormal];
//white
}
}
/*else
{
[cell.btnMail setImage:[UIImage imageNamed:@"MailGreen"] forState:UIControlStateNormal];
// green icon
}*/
}
[cell.btnCall addTarget:self
action:@selector(callDo:) forControlEvents:UIControlEventTouchDown];
[cell.btnSms addTarget:self
action:@selector(smsDo:) forControlEvents:UIControlEventTouchDown];
[cell.btnMail addTarget:self
action:@selector(mailDo:) forControlEvents:UIControlEventTouchDown];
[cell.btnStatus addTarget:self
action:@selector(Status:) forControlEvents:UIControlEventTouchDown];
[cell.btnAppointment addTarget:self
action:@selector(AddappointmentId:) forControlEvents:UIControlEventTouchDown];
[cell.btnCreatePlan addTarget:self
action:@selector(CreatePlan:) forControlEvents:UIControlEventTouchDown];
}
else
{
cell.lblFullname.text = [arrfullname objectAtIndex:indexPath.row];
cell.btnSms.hidden = YES;
cell.btnCall.hidden = YES;
cell.btnMail.hidden = YES;
cell.colorView.hidden =YES;
// cell.lblTime.text = [appointmenttime objectAtIndex:indexPath.row];
//cell.lblDate.text = [arrappointment_date objectAtIndex:indexPath.row];
NSString *dateStr = [NSString stringWithFormat:@"%@",[appointmenttime objectAtIndex:indexPath.row]];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];
NSLog(@"%@",date);
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"hh:mm a"];
NSString *depResult = [df stringFromDate:date];
cell.lblTime.text = depResult;
dateStr = [NSString stringWithFormat:@"%@",[arrappointment_date objectAtIndex:indexPath.row]];
// Convert string to date object
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-mm-dd"];
date = [dateFormat dateFromString:dateStr];
NSLog(@"%@",date);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date22 = [dateFormatter dateFromString:dateStr];
[dateFormatter setDateFormat:@"dd MMM yyyy"];
NSString *dateWithNewFormat = [dateFormatter stringFromDate:date22];
NSLog(@"dateWithNewFormat: %@", dateWithNewFormat);
// df = [[NSDateFormatter alloc]init];
// [df setDateFormat:@"dd MMM yyyy"];
// depResult = [df stringFromDate:date];
//
cell.lblDate.text = dateWithNewFormat;
}
/* UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor clearColor];
[cell setSelectedBackgroundView:bgColorView];*/
return cell;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
arrsearchresult = [arrfullname filteredArrayUsingPredicate:resultPredicate];
[self.tblAppoinment reloadData];
}
-(BOOL)searchDisplayController:(UISearchController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
这是我的.m文件 DisplayAppointmentViewController.m
2016-12-15 15:07:44.534 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7fb59aef6930'
*** First throw call stack:
(
0 CoreFoundation 0x000000010898ae65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108403deb objc_exception_throw + 48
2 CoreFoundation 0x000000010899348d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001088e090a ___forwarding___ + 970
4 CoreFoundation 0x00000001088e04b8 _CF_forwarding_prep_0 + 120
5 xxxxx 0x0000000107d629ee -[DisplayAppointmentViewController tableView:cellForRowAtIndexPath:] + 10894
6 UIKit 0x0000000109910e43 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
7 UIKit 0x0000000109910f7b -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
8 UIKit 0x00000001098e5a39 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2996
9 UIKit 0x000000010991a01c -[UITableView _performWithCachedTraitCollection:] + 92
10 UIKit 0x0000000109900edc -[UITableView layoutSubviews] + 224
11 UIKit 0x000000010986e4a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
12 QuartzCore 0x00000001095fa59a -[CALayer layoutSublayers] + 146
13 QuartzCore 0x00000001095eee70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
14 QuartzCore 0x00000001095eecee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
15 QuartzCore 0x00000001095e3475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
16 QuartzCore 0x0000000109610c0a _ZN2CA11Transaction6commitEv + 486
17 UIKit 0x00000001097b1f7c _UIApplicationHandleEventQueue + 7329
18 CoreFoundation 0x00000001088b6a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x00000001088ac95c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x00000001088abe13 __CFRunLoopRun + 867
21 CoreFoundation 0x00000001088ab828 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x000000010ed40ad2 GSEventRunModal + 161
23 UIKit 0x00000001097b7610 UIApplicationMain + 171
24 xxxxx 0x0000000107d50bbf main + 111
25 libdyld.dylib 0x000000010adfa92d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我的错误日志是
private static decimal? X = null;
if (tdataItems.Y != null)
{
X = tbldataItems.Y;
}
答案 0 :(得分:0)
Foundation 0x000000010e034888 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
Foundation 0x000000010df8a997 -[NSObject(NSKeyValueCoding) valueForKey:] + 280
Foundation 0x000000010dfc5319 -[NSFunctionExpression expressionValueWithObject:context:] + 1096
你崩溃日志说方法中谓词的键值存在问题
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
放置断点,检查代码运行时间并根据数据源更正谓词。