Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ios中更改搜索栏中的文本时,我的iphone应用程序崩溃_Iphone_Objective C - Fatal编程技术网

在ios中更改搜索栏中的文本时,我的iphone应用程序崩溃

在ios中更改搜索栏中的文本时,我的iphone应用程序崩溃,iphone,objective-c,Iphone,Objective C,我有一个应用程序,其中我正在使用带有表视图的搜索栏。当在搜索栏中输入特定单词并单击“搜索”按钮时,与该特定关键字匹配的所有值都会显示在表视图中。但当我再次单击搜索栏并开始删除特定单词时,然后我的应用程序崩溃。这是我在tableview中搜索文本和显示的代码 -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { if ([searcharray count]>0) { canSelectR

我有一个应用程序,其中我正在使用带有表视图的搜索栏。当在搜索栏中输入特定单词并单击“搜索”按钮时,与该特定关键字匹配的所有值都会显示在表视图中。但当我再次单击搜索栏并开始删除特定单词时,然后我的应用程序崩溃。这是我在tableview中搜索文本和显示的代码

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    if ([searcharray count]>0)
    {
        canSelectRow = YES;
        self.tblView.scrollEnabled = YES;
    }else {
        canSelectRow = NO;
        self.tblView.scrollEnabled = NO;
    }
    isSearchOn = YES;
    searchBar.showsCancelButton = YES;
    [searchBar setShowsCancelButton:YES animated:YES];
    searchBar.autocorrectionType = UITextAutocorrectionTypeNo;

}



-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)searchText 
{
    [searcharray removeAllObjects];

    if ([searchText length]>0) 
    {
        isSearchOn = YES;
        canSelectRow = YES;
        self.tblView.scrollEnabled = YES;
        [self searchTableView];
    }
    else {

        isSearchOn = NO;
        canSelectRow = NO;
        self.tblView.scrollEnabled = NO;
    }
    [self.tblView reloadData];

}

-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    searchBar.showsCancelButton = NO;

}


-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    searchBar.text = @"";
    testSearch = NO;
    canSelectRow = YES;
    self.tblView.scrollEnabled = YES;
    [searchBar resignFirstResponder];
    [self.tblView reloadData];
}


-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar1
{
    testSearch = TRUE;
    NSString *searchtext = searchBar.text;

    int tag =(NSNumber*) [[NSUserDefaults standardUserDefaults] integerForKey:@"buttontag"];
    if (tag==0)
    {
        //calling my api method to display on the tableview.    
    }
    else if(tag==1)
    {
        //calling my api method to display on the tableview.
    }
    else if(tag==2)
    {
        //calling my api method to display on the tableview.
    }
    else if(tag==3)
    {
        //calling my api method to display on the tableview.
    }
    else if(tag==4)
    {
        //calling my api method to display on the tableview.
    }
    else if(tag ==5)
    {
        //calling my api method to display on the tableview.
    }


    [searchBar resignFirstResponder];
}
在单元格中显示时,我使用的是searcharray

tableview cellForRowAtIndexPath
{
//testSearch is the bool variable that i have returned true when search button is clicked
if (testSearch)
    {
        //through the search arrray i am displaying in cell.
        NSDictionary *dict = [searcharray objectAtIndex:indexPath.row];

// app is crashing at this point.
        ****cell.lblPassion.text = [dict objectForKey:@"Title"];****
        cell.lblCost.text = [dict objectForKey:@"DescriptionMobile"];

        NSString *startdate =[dict objectForKey:@"StartDtm"];
        NSDate *newstartdate = [dateformatter dateFromString:startdate];
        NSString *custommessage = (NSString*)[dict objectForKey:@"OfferCustomMessage"];
        if ( custommessage !=nil && custommessage !=NULL && custommessage !=(NSString*) [NSNull null]) {

            cell.lblCustomMsg.hidden = NO;
            cell.lblCustomMsg.text = custommessage;
            cell.lblDiscount.hidden = YES;
            cell.lblDeal.hidden = YES;
            cell.lblStrikeout.hidden = YES;
            cell.strikeimage.hidden = YES;

        }
}

尝试zombies@ShivanRaptor它抛出此错误[NSCFString objectForKey:]:发送到实例0x5f404f0 2012-08-23 12:59:49.028***由于未捕获的异常“NSInvalidArgumentException”,终止应用程序,原因:'-[NSCFString objectForKey:]:未识别的选择器发送到实例0x5f404f0'中我在question@nielsbot它抛出此错误[NSCFString objectForKey:]:发送到实例0x5f404f0 2012-08-23 12:59:49.028***的无法识别的选择器由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[NSCFString objectForKey:]:发送到实例0x5f404f0的无法识别的选择器“看起来您正在将NSString实例添加到“searcharray”中,并尝试在cellForRowAtIndexPath方法中从中读取“NSDictionary”。您正在将objectForKey:message/selector传递给NSString,这导致应用程序崩溃,因为NSString是无法识别的选择器。