0

我阅读了有关 SplitViewControllers 的分配信息,但我绕着圈子走,因为我什么都不懂。

您有一个 masterviewcontroller 和一个 popoverview 作为条形按钮项(过滤器)

假设 masterviewcontroller 是一个 tableview 并且在 popoverview 是一个 uiview 控制器

在 iphone 上,我总是分配 masterviewcontroller 并在进行一些修改后更新参考,当您点击“搜索”按钮时,它会推送一个带有新数据的新控制器(想想看,也许这不是最好的主意)现在逻辑不再工作了。

我读过你必须互相引用控制器,所以我这样做了。

在过滤器控制器中(这是弹出视图)

.h

@property (strong, nonatomic) MasterViewController *masterviewController;
@property (weak, nonatomic) IBOutlet UISlider *filterPrice;

- (IBAction)filterSearch:(id)sender;


.m
- (IBAction)filterSearch:(id)sender {

self.masterviewController.filterSearchPrice = [NSNumber numberWithInt:self.filterPrice.value];
[self.masterviewController performFilterSearch];
}

performFilterSearch 检查字段,使用过滤器名称和 json 对象调用 url,解析并重新加载数据。

现在我希望 masterviewcontroller 显示新数据,但这并没有发生,实际上什么也没发生......

更新这是 FilterSearch:

-(void)performFilterSearch
{

[queue cancelAllOperations];
[[AFImageCache sharedImageCache] removeAllObjects];
[[NSURLCache sharedURLCache] removeAllCachedResponses];

isLoading =YES;
[self.tableView reloadData];

searchResults = [NSMutableArray arrayWithCapacity:10];

NSURL *url = [self urlFilterWithSearchPrice:filterSearchPrice];
NSLog(@"%@",url);

NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
                                     JSONRequestOperationWithRequest:request
                                     success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                                         [self parseDictionary:JSON];


                                         isLoading = NO;
                                         [self.tableView reloadData];

                                     }
                                     failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
                                         [self showNetworkError];
                                         isLoading = NO;
                                         [self.tableView reloadData];
                                     }];

operation.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
[queue addOperation:operation];

}

顺便说一句,当我在 filterSearch 中进行 Nslog 以检查其是否已更新时:

NSLog(@"%d",self.masterviewController.filterSearchPrice);
NSLog(@"%d",[self.filterTypeSegmentedControl selectedSegmentIndex]);

第一个永远不会更新第二个会偏离课程更新

更新2:(我如何启动popview):

我在具有操作的 masterviewcontrollers 导航上添加了一个条形按钮项。我从 masterviewcontroller -> filtercontroller 添加了一个popover segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

filterPopOver  = [(UIStoryboardPopoverSegue *)segue popoverController];

}

- (IBAction)filterPopButton:(id)sender {

if (filterPopOver){
    [filterPopOver dismissPopoverAnimated:YES];
}
else{
    [self performSegueWithIdentifier:@"showFilterPopover" sender:sender];
}
}
4

1 回答 1

1

When you launch your filterController, you need to pass in a reference to the MasterViewController. You have a property for it in the filter controller, but you never assign a value to that property.

After Edit:

Your prepareForSegue method should look like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    FilterController *fc = (FilterController *)segue.destinationViewController;
    fc.masterViewController = self;
}

Make sure that you've imported MasterViewController.h into you FilterController.m

于 2013-01-12T18:15:13.493 回答