简体   繁体   English

当我在搜索栏中键入内容时,我的应用崩溃

[英]when i type in search bar my app crashes

this is my .h file.in this file i declare array for searchresult and mail array that i want to use for filter is arrfullname. 这是我的.h文件。在此文件中,我声明用于searchresult的数组,并且要用于过滤器的邮件数组是arrfullname。

DisplayAppointmentViewController.h 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

this is my .m file DisplayAppointmentViewController.m 这是我的.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;
}

and my errorlog is 我的错误日志是

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
  Foundation                          0x000000010e034888 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
   Foundation                          0x000000010df8a997 -[NSObject(NSKeyValueCoding) valueForKey:] + 280
   Foundation                          0x000000010dfc5319 -[NSFunctionExpression expressionValueWithObject:context:] + 1096

You crash log said there is issue in key value of predicate in method 您崩溃日志说方法中谓词的键值有问题

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

Place break-point, check your code run time and correct your predicate according to data-source. 放置断点,检查代码运行时间,并根据数据源更正谓词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在搜索栏中键入字母时,应用程序崩溃 - Application crashes when type a letter in search bar 在Swift 4的搜索栏中搜索超过2个单词时,应用崩溃 - App Crashes when searched for beyond 2 words in Search Bar in Swift 4 滚动并在搜索栏上按取消时,应用程序崩溃 - App crashes when scrolling and pressing cancel on search bar 单击选项卡栏控制器时,应用程序崩溃 - App Crashes when I click Tab Bar Controller 单击侧栏菜单时应用程序崩溃 - App crashes when I click on side bar menu 当我在搜索栏中键入以检索Google图书信息时,我的表格视图未重新加载 - My Table View is not Reloading When I type in the Search Bar to Retrieve the Google Books Information 打开搜索栏时导航栏正在隐藏 - Navigation bar is hiding when i open my search bar 每次我点击搜索栏时ios应用程序崩溃,同时从parse.com撤消数据 - ios app crashes each time i click on the search bar, while retreving data from parse.com 当我尝试在模型中保存数据时,应用程序崩溃 - App crashes when I am trying to saved data in my model 当我将UITableViewCell作为AnyObject传递时,我的应用程序崩溃了? 到另一个功能 - My App crashes when I pass a UITableViewCell as AnyObject? to an other function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM