gpt4 book ai didi

ios - 将 NSString 与来自 Parse.com 的 NSArray 进行比较(Obj-c)

转载 作者:行者123 更新时间:2023-11-29 10:28:32 24 4
gpt4 key购买 nike

我正在尝试通过 if 语句将 NSStringNSArray 进行比较。这是我尝试过的:

-(void)queryParseMethod {
//PFQuery *query = [PFQuery queryWithClassName:classNameString];
PFQuery *query = [PFQuery queryWithClassName:@"SaveClass2"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
_barcodeArray = [[NSArray alloc]initWithArray:objects];
//[_tableView reloadData];
}else{
NSLOG(@"ERROR");
}
}];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self queryParseMethod];

NSIndexPath *indexPath;
int barcodInt = indexPath.row %1000000;
PFObject *barcodeObject = [_barcodeArray objectAtIndex:barcodInt];
NSArray *secondBarcodeArray;
secondBarcodeArray = [barcodeObject objectForKey:@"RNG1"];

if ([[secondBarcodeArray objectAtIndex:barcodInt] isEqualToString:_label.text]){
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"FOUND" message:@"THE BARCODE IS CORRECT!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
}else{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"NOT FOUND" message:@"THE BARCODE IS INCORRECT!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
};
}

但它总是显示“未找到”警报 View ,我确信类是正确的,列也是正确的,但它不会工作。任何帮助将不胜感激。

最佳答案

只要您的 _barcodeArray 是在后台线程中分配的(我相信在其中运行 findObjectsInBackgroundWithBlock:,在您尝试获取对象 barcodeObject 的位置 from _barcodeArray 后者是空的(可以是也可以不是)。你有经典的竞争条件。如果你真的需要在后台运行这个查找对象 block ,你应该考虑使用一些同步机制 - 类似于 dispatch_semaphore。或者,正如我所推测的,您不需要调用 findObjectsInBackgroundWithBlock: 而是使用它的同步对应物(如果存在的话)。

关于ios - 将 NSString 与来自 Parse.com 的 NSArray 进行比较(Obj-c),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30912556/

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