我想从我的SearchViewController
发送布尔值didAddNewItem
到MatchCenterViewController
,然后根据布尔值的状态运行一个函数。我试图发送一个didAddNewItem
值YES
到我的目的地,MatchCenterViewController
,但它似乎没有正确发送,因为下面的函数从不运行。Bool值未被发送到目标ViewController
下面是我从SearchViewController发送它(编辑以反映罗布的回答):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ShowMatchCenterSegue"]) {
_didAddNewItem = YES;
MatchCenterViewController *controller = (MatchCenterViewController *) segue.destinationViewController;
NSLog(@"we're about to set controller values before segueing to MC");
// Send over the matching item criteria
controller.itemSearch = self.itemSearch.text;
controller.matchingCategoryId = self.matchingCategoryId1;
controller.matchingCategoryMinPrice = self.matchingCategoryMinPrice1;
controller.matchingCategoryMaxPrice = self.matchingCategoryMaxPrice1;
controller.matchingCategoryCondition = self.matchingCategoryCondition1;
controller.matchingCategoryLocation = self.matchingCategoryLocation1;
controller.itemPriority = self.itemPriority;
[self.tabBarController setSelectedIndex:1];
}
}
这里的地方我试图利用它的目的地,MatchViewController:
- (void)viewDidAppear:(BOOL)animated
{
if (_didAddNewItem == YES) {
NSLog(@"well then lets refresh the MC");
// Start loading indicator
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0);
[self.view addSubview: activityIndicator];
[activityIndicator startAnimating];
// Disable ability to scroll until table is MatchCenter table is done loading
self.matchCenter.scrollEnabled = NO;
_matchCenterDone = NO;
// Add new item to MatchCenter Array with the criteria from the matching userCategory instance, plus the search term
[PFCloud callFunctionInBackground:@"addToMatchCenter"
withParameters:@{
@"searchTerm": self.itemSearch,
@"categoryId": self.matchingCategoryId,
@"minPrice": self.matchingCategoryMinPrice,
@"maxPrice": self.matchingCategoryMaxPrice,
@"itemCondition": self.matchingCategoryCondition,
@"itemLocation": self.matchingCategoryLocation,
@"itemPriority": self.itemPriority,
}
block:^(NSString *result, NSError *error) {
if (!error) {
NSLog(@"'%@'", result);
self.matchCenterArray = [[NSArray alloc] init];
[PFCloud callFunctionInBackground:@"MatchCenter3"
withParameters:@{}
block:^(NSArray *result, NSError *error) {
if (!error) {
_matchCenterArray = result;
[_matchCenter reloadData];
[activityIndicator stopAnimating];
// Reenable scrolling/reset didAddNewItem bool
_matchCenterDone = YES;
self.matchCenter.scrollEnabled = YES;
//_didAddNewItem = NO;
NSLog(@"Result: '%@'", result);
}
}];
}
}];
}
}
我确定它已经正确设置为两个ViewControllers头部的属性,所以我不确定它为什么没有正确设置目标VC中的值。我知道一个事实,即addToMatchCenter
函数正确运行没有错误,所以它应该工作。
@property (assign) BOOL didAddNewItem;
你什么时候推MatchCenterViewController?如果您在exics块之前推送此视图控制器,则不会为didAddNewItem指定值。 – 2014-10-17 06:14:23
这里的问题与当segue执行时的块一样,那么将调用你的MatchCenterViewController的viewDidload方法,而不管你被调用的块如何。所以你的布尔值不会被设置,并且你的viewDidlaod方法被调用,它不具有你的布尔值。因此请检查您的流量并在其中进行更改。 – nikhil84 2014-10-17 06:17:02