Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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
Iphone 在视图中设置searchBar.text未加载_Iphone_Objective C_Ios_Uisearchbar - Fatal编程技术网

Iphone 在视图中设置searchBar.text未加载

Iphone 在视图中设置searchBar.text未加载,iphone,objective-c,ios,uisearchbar,Iphone,Objective C,Ios,Uisearchbar,当我从视图1推到视图2时,我试图设置我的searchBar.text。我正在将一个字符串成功地传递到视图2中,但是我希望将该字符串设置为searchBar.text以筛选我的表。到目前为止,这是我的代码,但似乎不起作用 - (void)viewDidLoad { [super viewDidLoad]; self.title = NSLocalizedString(@"Places", nil); self.managedObjectContext = [self get

当我从视图1推到视图2时,我试图设置我的searchBar.text。我正在将一个字符串成功地传递到视图2中,但是我希望将该字符串设置为searchBar.text以筛选我的表。到目前为止,这是我的代码,但似乎不起作用

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = NSLocalizedString(@"Places", nil);
    self.managedObjectContext = [self getContext];
    UIBarButtonItem * sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStyleBordered target:self action:@selector(sort)];

    self.navigationItem.rightBarButtonItem = sortButton;
    [sortButton release];

    //HIT WS TO SEE LAST UPDATED AND COMPARE TO STORED LAST UPDATED DATE
    //IF WS HAS NEWER DATE,BLOW CD AWAY AND CALL getRSSDAta

    self.searchBar.delegate = self;
    self.title = @"Results";
    self.navigationController.navigationBarHidden = NO;

    __tableView.delegate = self;
    __tableView.dataSource = self;
    searchedData = [[NSMutableArray alloc]init];
    tableData = [[NSMutableArray alloc]init];
    [tableData addObjectsFromArray:_PlaceArray];//on launch it should display all the records 

    [recurringArray initWithObjects:@"Alphabetical",@"Rating Low to High", @"Rating Hight to Low", nil];

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_texture.png"]];

    self.view.backgroundColor = background;

    [background release];


    recurringDate = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 190, 320, 200)];
    recurringDate.showsSelectionIndicator = YES;
    recurringDate.delegate = self;
    [recurringDate selectRow:0 inComponent:0 animated:YES];
    [self.view addSubview:recurringDate];

    recurringDate.hidden = YES;

    NSLog(@"search text is %@", self.search);

    searchBar.text = self.search;
    [self searchBarSearchButtonClicked:searchBar];

}

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    // only show the status bar’s cancel button while in edit mode
    useSearchData = YES;
    self.searchBar.showsCancelButton = YES;
    self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    // flush the previous search content
    [tableData removeAllObjects];
}

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

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{

    if([searchText isEqualToString:@""] && [__searchBar.text isEqualToString:@""]){       //if nothing is in the search bar show normal table
        useSearchData = NO;
        [self.tableView reloadData];
        [self.searchBar resignFirstResponder];
        return;
    }
    else
    {
            searchText = __searchBar.text;

        useSearchData=YES;

        NSPredicate * p = [NSPredicate predicateWithFormat:@"name contains[cd] %@",searchText]; //comparing stored locations to searchText

        self.searchResults = [CoreDataBasicService fetchResultsForEnity:@"Place" WithPredicate:p andSortDiscriptor:@"name" Ascending:YES];

        [self.tableView reloadData];
    }
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    useSearchData = NO;

    [self.searchResults removeAllObjects];
    [self.tableView reloadData];

    [self.searchBar resignFirstResponder];
    self.searchBar.text = @"";


}

-(void)searchBarSearchButtonClicked:(UISearchBar *)_searchBar
{
    [searchBar resignFirstResponder];
}

听起来可能有点傻,但请确保您将其连接到IB中,当我干扰某些代码时,我忘记了执行此操作

搜索功能已经在过滤原始表。我只想在第一个视图中设置搜索文本,然后在第二个视图中将该字符串推送到搜索栏。字符串通过很好,我只是不能用字符串self.search设置搜索栏文本。