UISearchBartextfield -webview被调用。新文本架构不再支持此方法

时间:2014-03-22 17:12:21

标签: ios7 xcode5 uisearchbar

我收到此错误,当用户开始输入查询(XCODE 5.1)时,我的搜索功能不执行任何操作。

我不知道-webView是如何与此错误相关的,因为我没有在这些文件中使用webView。任何意见,将不胜感激。谢谢。

OrdersViewController.h

#import <UIKit/UIKit.h>

@interface OrdersViewController : UITableViewController <UISearchBarDelegate>

//NSmurray is set because we want to edit/move items as well (this will be implemented later)
@property (nonatomic, strong) NSMutableArray *jsonParseArray;
@property (nonatomic, strong) NSMutableArray *ordersArray;
@property (strong, nonatomic) IBOutlet UISearchBar *searchOrders;
@property (nonatomic, strong ) NSMutableArray *orderSearchResults;

#pragma mark -
#pragma mark Class Methods

-(void) retrieveOrderData;

@end

OrdersViewController.m

#import "OrdersViewController.h"
#import "Order.h"
#import "OrderDetailViewController.h"
#define getDataURL @"http://gkhns-macbook-pro.local/gj-3.php"
@interface OrdersViewController ()

@end

@implementation OrdersViewController
@synthesize jsonParseArray, ordersArray;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

   //
   // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    self.title = @"ORDERS";
    [self retrieveOrderData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.


}

-(void)searchThroughOrders {
    self.orderSearchResults = nil;

    //gettig the text that is entered in the search bar and it creates nspredicated self containes the search and this text will be replaced by search field
    NSPredicate *orderResultsPredicate = [NSPredicate predicateWithFormat:@"SELF contains [search] %@", self.searchOrders.text];

//filtering the predicate that is set before
    self.orderSearchResults = [[self.ordersArray filteredArrayUsingPredicate:orderResultsPredicate] mutableCopy];
}

//detect when the user typed in the search

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    [self searchThroughOrders];

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

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

      //are we in regular table view or search display view? Lets check that
    if (tableView == self.tableView)

    {
    return ordersArray.count;

    }
    else{
        [self searchThroughOrders];
         // Return the number of rows in the section.
    return self.orderSearchResults.count;
    }

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"OrderCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];



   if(cell==nil){
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
       cell.selectionStyle=UITableViewCellStyleDefault;

    }
     if (tableView== self.tableView)
           // Configure the cell...

    {Order *orderObject;
        orderObject = [ordersArray objectAtIndex:indexPath.row];
        cell.textLabel.text=orderObject.order_id;
        cell.detailTextLabel.text=orderObject.firstname;
    }
    else

    {

        cell.textLabel.text = self.orderSearchResults [indexPath.row];

    }






    //accessory

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    }



/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark - Navigation

 //In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.


    if ([[segue identifier] isEqualToString:@"pushOrderDetailView"]){
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        Order* object = [ordersArray objectAtIndex:indexPath.row];

        [[segue destinationViewController] getOrder:object];





    }
}






#pragma mark -
#pragma mark Class Methods

-(void) retrieveOrderData{

    NSURL * url = [NSURL URLWithString:getDataURL];
    NSData * data = [NSData dataWithContentsOfURL:url];
    jsonParseArray=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

    //orders array

    ordersArray= [[NSMutableArray alloc]init];

    //loop through the jason array

    for (int i=0; i<jsonParseArray.count; i++)

    {
    //create the order object

NSString *oId = [[jsonParseArray objectAtIndex:i] objectForKey:@"order_id"];
NSString *eMail = [[jsonParseArray objectAtIndex:i] objectForKey:@"email"];
NSString *fName = [[jsonParseArray objectAtIndex:i] objectForKey:@"firstname"];
NSString *lName = [[jsonParseArray objectAtIndex:i] objectForKey:@"lastname"];
NSString *sName = [[jsonParseArray objectAtIndex:i] objectForKey:@"store_name"];
NSString *iPrefix = [[jsonParseArray objectAtIndex:i] objectForKey:@"invoice_prefix"];
NSString *pAddress1 = [[jsonParseArray objectAtIndex:i] objectForKey:@"payment_address_1"];
NSString *sPaymentAddress2 = [[jsonParseArray objectAtIndex:i] objectForKey:@"payment_address_2"];

        //add order to orders array

        [ordersArray addObject:[[Order alloc]initWithOrderId: (NSString *)oId andInvoicePrefix: (NSString*)iPrefix andStoreName:(NSString*)sName andFirstName:(NSString*)fName andLastName:(NSString*)lName andEmail:(NSString*)eMail andPaymentAddress1:(NSString*)pAddress1  andPaymentAddress2:(NSString*)sPaymentAddress2]];
    }

    //reload the view

    [self.tableView reloadData];



}

@end

1 个答案:

答案 0 :(得分:0)

我只使用搜索栏而不是搜索栏和可能导致此问题的搜索显示控制器。

还对searchdisplay控制器实现进行了一些更改,修改了问题。

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

    return YES;

}

-(void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView{

    [tableView registerClass:[CustomOrdersCell class] forCellReuseIdentifier:@"OrderCell"];

}


-(void)searchThroughOrders:(NSString *)searchText scope:(NSString*)scope {


    //getting the text that is entered in the search bar and it creates nspredicated self containes the search and this text will be replaced by search field
    NSPredicate *orderResultsPredicate = [NSPredicate predicateWithFormat:@"order_id contains[c] %@", searchText];

//filtering the predicate that is set before
    _orderSearchResults = [ordersArray filteredArrayUsingPredicate:orderResultsPredicate];

}