ios - 如何在 block 外部保持引用有效(启用ARC)?

标签 ios objective-c cocoa-touch automatic-ref-counting

我的问题是关于在完成处理程序块之外保持引用有效。
首先,请看一下我的TableViewController:

@interface KMTweetTableViewController : 
UITableViewController

@property (weak) ACAccount      
 *selectedAccount;

@property  NSMutableArray  *tweetTextBank ;

@end

- (void)viewDidLoadKMTweetTableViewController方法中,我创建了一个名为SLRequestuserTimeLineRequest实例。事实证明,它负责向Twitter请求用户的时间轴。

然后,我尝试根据状态“文本”属性制作一个数组。我使用这段代码来做到这一点:
[userTimeLineRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSArray *userTimeline = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:Nil];
            int counter ; NSMutableArray *returner = [NSMutableArray alloc]  ;
            for (counter= 1 ; counter <= userTimelineCountReference ; counter++) {
                NSDictionary  *status = [userTimeline objectAtIndex: counter-1]   ;
                NSString  *tweetText = [status objectForKey:@"text"];
                [self.tweetTextBank addObject:tweetText ];
            }
            NSLog(@"%@" , self.tweetTextBank) ;
        });

    }];
dispath_async块中的代码运行良好,但是当NSLog()触发时,我只得到null。我认为这是因为tweetText的引用在dispath_async块的末尾被终止了...那么,在启用ARC的情况下,如何使该引用保持 Activity 状态呢?

谢谢你们

最佳答案

由于尚未初始化数组,因此将为空。因此,首先您需要初始化可变数组。

self.tweetTextBank=[NSMutableArray array];

关于ios - 如何在 block 外部保持引用有效(启用ARC)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19889107/

相关文章:

iphone - Storyboard自定义表标题

ios - 从 "Copy Bundle Resources"中删除 SDK?

objective-c - Objective-C - 如果在 CGRectmake 上声明?

iphone - 如何将 UITableView 滚动到不包含行的部分?

html - 仅使用粗体和斜体将 NSAttributedString 转换为 HTML

iOS Mystery crash w libsystem_kernel.dylib

c# - C# .NET 方法或习惯用法中 Objective-C 调度队列的等价物

objective-c - 如何激活没有标题栏的窗口

iphone - 在数字键盘上显示丢弃和完成按钮

iphone - 在 iPhone 应用程序的 map 上通过适当的图标显示酒店(和附近的地方)