2016-12-15 4 views
0

c'est mon fichier .h dans ce fichier je déclare le tableau pour searchresult et mail array que je veux utiliser pour le filtre est arrfullname.quand je tape dans la barre de recherche mon application plante

DisplayAppointmentViewController.h

// 
// DisplayAppointmentViewController.h 
// AffordPlan 
// 
// Created by apple on 17/08/16. 
// Copyright © 2016 Taxsmart. All rights reserved. 
// 

#import <UIKit/UIKit.h> 
#import <MessageUI/MessageUI.h> 
#import "CustomClass.h" 
#import "AppoinmentTableViewCell.h" 
#import <CoreTelephony/CTTelephonyNetworkInfo.h> 
#import <CoreTelephony/CTCarrier.h> 
#import "AddAppoinmentViewController.h" 
#import "CreatePlanViewController.h" 
#import "LeadViewController.h" 
#import "Sqlite.h" 
#import "outComeViewController.h" 

@class RadioButton; 


@interface DisplayAppointmentViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,UISearchControllerDelegate,UISearchBarDelegate,UISearchResultsUpdating,MFMailComposeViewControllerDelegate,MFMessageComposeViewControllerDelegate> 
{ 




    NSArray *arrsearchresult; 


    NSMutableArray *arrfullname; 
    NSMutableArray *arrdatetime; 

    NSMutableArray *arrappointment_date; 
    NSMutableArray *appointmenttime; 



} 

@property (strong, nonatomic) IBOutlet UITableView *tblAppoinment; 
@property (strong, nonatomic) IBOutlet RadioButton *btnSearchByName; 
@property (strong, nonatomic) IBOutlet RadioButton *btnSearchByDate; 
@property (strong, nonatomic) IBOutlet UISearchBar *searchResultBar; 

- (IBAction)btnSearchByNamePress:(id)sender; 
- (IBAction)btnSearchByDatePress:(id)sender; 

@property CustomClass *customClass; 

- (IBAction)btnBackPressed:(id)sender; 


@end 

c'est mon fichier .m DisplayAppointmentViewController.m

- (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; 
} 

et mon errorlog est

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 
+0

Qu'est-ce que le journal de panne? –

+0

2016-12-15 13: 02: 10.836 AffordPlan [2884: 91271] *** App terminaison due à l'exception non interceptée 'NSUnknownKeyException', raison: '[ valueForUndefinedKey:]: cette classe n'est pas codée par valeur clé- conforme pour le nom de la clé. *** Première pile d'appels: – sp309

+0

Qu'est-ce que 'name' dans votre prédicat? –

Répondre

0
Foundation       0x000000010e034888 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226 
    Foundation       0x000000010df8a997 -[NSObject(NSKeyValueCoding) valueForKey:] + 280 
    Foundation       0x000000010dfc5319 -[NSFunctionExpression expressionValueWithObject:context:] + 1096 

Crashlog Vous avez dit il y a question de la valeur clé du prédicat dans la méthode

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope 

Lieu point de rupture, vérifiez votre temps d'exécution de code et corriger votre prédicats selon la source de données.

+0

mon application se bloque après cette ligne dans - (void) filterContentForSearchText: (NSString *) portée searchText: (NSString *) méthode de portée: arrsearchresult = [arrfullname filteredArrayUsingPredicate: resultPredicate]; – sp309

+0

je change ma valeur de clé de predicate.now j'ai eu ce journal d'erreur. – sp309