UISearchBartextfield -webview called.this method is no longer supported with the new text architecture

StackOverflow https://stackoverflow.com/questions/22580843

  •  19-06-2023
  •  | 
  •  

Question

I am getting this error and my search function does nothing when the user starts typing a query( XCODE 5.1).

I dont know how the -webView is related to this error as I have not used webView in these files. Any advice would be appreciated. Thank you.

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
Was it helpful?

Solution

I was using searchbar only instead of search bar and the search display controller which may have caused this issue.

Also done a few changes to the searchdisplay controller implementation below which fixed the issue.

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top