局部变量类为null

时间:2015-09-02 14:35:35

标签: ios restkit uiactivity

我有一个问题。 RestKit我在我的应用程序中使用。当我通过网络接收数据时,我将它们保存在对象中,然后使用该类的各个字段。 在我的情况下,我得到一篇文章,其中有一个URL字段,在UIActivity中用于在社交网络中发送链接。 当我按下UIAсtivity调用处理函数时,我得到的URL为NULL。我不明白为什么会这样。

NewsDetailViewController.h

@property (nonatomic,strong) NSString *URL;

NewsDetailViewController.m

@interface NewsDetailViewController() {
   NSString *URL;
}

@synthesize URL;

[[RKObjectManager sharedManager] getObjectsAtPath:route parameters:params
                                          success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
Article *article = [mappingResult.array firstObject];
 self.URL = article.url;
                                          }
                                          failure:^(RKObjectRequestOperation *operation, NSError *error) {
                                              NSLog(@"Error response': %@", error);
                                          }];

-(void)socialSharing:sender {

dispatch_queue_t queue = dispatch_queue_create("openActivityIndicatorQueue", NULL);

dispatch_async(queue, ^{
    NSArray *itemsToShare = @[self.URL];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
        activityVC.excludedActivityTypes = @[UIActivityTypeAirDrop];
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        [self presentViewController:activityVC animated:YES completion:nil];
    });
});
}

初始化按钮

_items = [[self.toolBar items] mutableCopy];
UIBarButtonItem *shareBtn = [[UIBarButtonItem alloc]     initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(socialSharing:)];
[_items addObject:shareBtn];
[self.toolBar setItems:_items animated:YES];

内部功能socialSharing:sender我的变量self.URL为NULL。我不明白为什么?

0 个答案:

没有答案