我使用DISTINCT
获取数据但我必须在收集所有数据时使用数据。我不知道如何实现回调或任何在检索完所有数据并准备好使用后会提醒我的事情。有没有办法得到警报?
代码:
findObjectsInBackgroundWithBlock
答案 0 :(得分:0)
您需要使用 Block
声明block types
(在此选择您的typedef void (^YourBlock)(NSArray *array, NSError *error);
)
block
在方法中添加findObjectsInBackgroundWithBlock
和- (void) yourMethod:(YourBlock)block {
[query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
//Do your things here if you want change something.
//For instance: convert types, convert errors.
block(array, error); //Is called when every thing is retrieve.
}
}
。
SomeClass *someClass = [SomeClass alloc]init];
[[object getScoresFromParse:^(NSArray *array, NSError *error) {
//Everything complete here.
}];
在应用
中调用您的方法 private void viewMode_Click(object sender, EventArgs e)
{
if (sender is ToolStripMenuItem)
{
ToolStripMenuItem tlStrpMI = (ToolStripMenuItem)sender;
_selectedMode = (DisplayMode)ctxtMenuVw.Items.IndexOf(tlStrpMI)
switch (_selectedMode)
{
case DisplayMode.ScaleToFit:
panelPhoto.AutoScroll = false;
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
panelPhoto.Invalidate();
break;
case DisplayMode.StretchToFit:
panelPhoto.AutoScroll = false;
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
panelPhoto.Invalidate();
break;
case DisplayMode.ActualSize:
panelPhoto.AutoScroll = true;
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, false);
panelPhoto.Invalidate();
break;
default:
break;
}
}
}
答案 1 :(得分:0)
您可以使用块。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[query findObjectsInBackgroundWithBlock:^(NSArray* array, NSError* error)
{
if(!error)
{
if([array count] > 0)
{
PFObject* relationship = [array objectAtIndex:0];
if([relationship.objectId length] > 0)
{
// It will be called when Parse finishes.
dispatch_async(dispatch_get_main_queue(), ^{
if([[relationship objectForKey:@"initiatedBy"] isEqualToString:parseID]) // relationship initiated by current user -youLike
{
[youLike addObject:relationship];
NSLog(@"youLike added");
}
else
{
[likeYou addObject:relationship];
NSLog(@"likeYou added");
}
// [...yourcode...]
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Custom error when cycling through user relationships: objectId is nil");
});
}
}
}
}];
}];