gpt4 book ai didi

ios - 如何访问由另一种方法中的解析云代码返回的变量

转载 作者:行者123 更新时间:2023-11-28 22:05:53 25 4
gpt4 key购买 nike

我有一个方法:

- (IBAction)nextButton:(id)sender
{
if (self.itemSearch.text.length > 0) {
[PFCloud callFunctionInBackground:@"eBayCategorySearch"
withParameters:@{@"item": self.itemSearch.text}
block:^(NSDictionary *result, NSError *error) {
NSLog(@"'%@'", result);

// Parses results

NSArray *resultArray = [result objectForKey:@"results"];

// Number of Top Categories
NSDictionary *dictionary0 = [resultArray objectAtIndex:0];
NSNumber *numberOfTopCategories = [dictionary0 objectForKey:@"Number of top categories"];

// Ids of the Top Categories
NSDictionary *dictionary1 = [resultArray objectAtIndex:1];
NSArray *topCategoryIdsArray = [dictionary1 objectForKey:@"Top category Ids"];

// Names of the Top Categories
NSDictionary *dictionary2 = [resultArray objectAtIndex:2];
NSArray *topCategoryNamesArray = [dictionary2 objectForKey:@"Top category names"];

// Number of Top Categories matching User Categories
NSDictionary *dictionary3 = [resultArray objectAtIndex:3];
NSNumber *numberOfMatches = [dictionary3 objectForKey:@"Number of matches"];

// Names of Top Categories matching User Categories
NSDictionary *dictionary4 = [resultArray objectAtIndex:5];
NSString *matchingCategoryCondition = [dictionary4 objectForKey:@"Matching Category Condition"];




// Defines where each topCategory name will come from
self.topCategory1 = [topCategoryNamesArray objectAtIndex:0];
if ([numberOfTopCategories intValue] == 2) {
self.topCategory2 = [topCategoryNamesArray objectAtIndex:1];
}

// Defines where each topCategory ID will come from
self.topCategoryId1 = [topCategoryIdsArray objectAtIndex:0];
if ([numberOfTopCategories intValue] == 2) {
self.topCategoryId2 = [topCategoryIdsArray objectAtIndex:1];
}


if (!error) {

// Decides which segue is taken based on results

// if 1 match found clear categoryResults and top2 array
if ([numberOfMatches intValue] == 1 ){
[self performSegueWithIdentifier:@"ShowMatchCenterSegue" sender:self];
}

// if 2 matches found
else if ([numberOfMatches intValue] == 2){
[self performSegueWithIdentifier:@"ShowUserCategoryChooserSegue" sender:self];
//default to selected categories criteria -> send to matchcenter -> clear categoryResults and top2 array
}

// if no matches found, and 1 top category is returned
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 1) {
[self performSegueWithIdentifier:@"ShowCriteriaSegue" sender:self];
}

// if no matches are found, and 2 top categories are returned
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 2) {
[self performSegueWithIdentifier:@"ShowSearchCategoryChooserSegue" sender:self];
}

}
}];
}
}

调用 Parse 云代码函数,并返回各种值。特别是一个值,matchingCategoryCondition,我想在 prepareForSegue 方法中使用,如下所示:

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

if ([segue.identifier isEqualToString:@"ShowMatchCenterSegue"]) {
MatchCenterViewController *controller = (MatchCenterViewController *) segue.destinationViewController;


// 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.text,
// @"categoryId": self.matchingCategoryCondition,
// @"minPrice": self.minPrice,
// @"maxPrice": self.maxPrice,
@"itemCondition": matchingCategoryCondition,
// @"itemLocation": self.itemLocation
}
block:^(NSString *result, NSError *error) {

if (!error) {
NSLog(@"'%@'", result);
}
}];



// Send over the search query
controller.itemSearch = self.itemSearch.text;
}
}

但是,我收到一条错误消息,指出 matchingCategoryCondition 是未声明的标识符。我怎样才能让它可用于像这样的方法?

最佳答案

按照 NobodyNada 的建议,一种方法是使用属性。一种稍微简单的方法是利用添加发送者参数的 performSegue 变种:

[self performSegueWithIdentifier:@"whatever" sender:matchingCategoryCondition];

这将在您的 prepare for segue 方法的 sender 参数中可用:

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

NSString *matchingCategoryCondition = (NSString *)sender;
// ...

但是代码可能还有另一个问题,即在 segue 期间异步解析调用的性能。您预计电话何时结束?目标 View Controller 是否取决于结果?如果是这样,您需要在 performSegue: 之前启动该请求,然后从其完成 block 中调用 performSegue。

关于ios - 如何访问由另一种方法中的解析云代码返回的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23975002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com