【问题标题】:Visibility (scope) of variables in block handler块处理程序中变量的可见性(范围)
【发布时间】:2012-03-16 07:15:40
【问题描述】:

这听起来可能是一个新手问题,但我是 iOS 开发新手。

arg1arg2 在以下代码中的 completionHandler 块中是否可见?如果不是,将这些变量传递给块的正确方法是什么?

- (void)addCurrentLocationNameToDB:(CLLocation *)location param1:(NSString*)arg1 param2:(NSString*)arg2 
{
     CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
     [geoCoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) 
     {
             [self locationNameDidReceive:locationName forLocation:location forTrip:arg1 waypoint:arg2];
     }];
}

【问题讨论】:

    标签: iphone objective-c ios scope block


    【解决方案1】:

    是的,只需使用它们。在此处阅读有关块的更多信息: http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Blocks/Articles/bxVariables.html

    (这是街区的一大优势 - 你几乎停留在周围的范围内)

    【讨论】:

      猜你喜欢
      • 2014-04-05
      • 1970-01-01
      • 2011-10-23
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多