我想延迟方法的调用,直到其他代码首先完成。
这是一个按钮触发的动作。用户扫描条形码。我希望在调用其他方法之前完成它:[self performSelector:@selector(otherMethod:) withObject:nil afterDelay:0.5];
我尝试使用延迟,但这不好且不可预测。
- (IBAction) scanButtonTapped
{
NSLog(@"TBD: scan barcode here...");
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
[self performSelector:@selector(otherMethod:) withObject:nil afterDelay:0.5];
}