這是關於Block語句的問題。我的問題是如何在塊句中變出來。請看我的代碼。下面的代碼不能很好地工作。Block sentense以外的變量使用
__block NSURL *ssURL
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
ssURL = [NSURL URLWithString:[JSON valueForKeyPath:@"screenshot"]];
[self currentEntry].ogImageURL = ssURL;
NSLog(@"%@", ssURL); // -> "http://correct.address"
} failure:nil];
[operation start];
另外我設置變量ogImageURL如下:
@property (copy, atomic) NSURL *ogImageURL;
缺貨完成塊;所述的NSLog顯示 「(空)」 明顯。我想使用塊句子之外的變量。這很奇怪。
我必須從塊外部獲取變量,因爲我想創建表格視圖,在該視圖中單元格調用將自我信息獲取到數組中。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if (indexPath.row < self.itemsArray.count) {
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
UIImageView *imageViewOgImage = (UIImageView *)[cell viewWithTag:5];
NSURL *ogImageURL = [[self.itemsArray objectAtIndex:indexPath.row] ssURL];
完整的源是這個第186行:https://github.com/weed/p120711_TechMovie/blob/120723/TechMovie/RSSParser.m
如何使用'AFJSONRequestOperation'完成塊?我想在塊外做幾件事情。我嘗試過'[waitUntilFinished操作]',但我不太順利。 – weed 2012-08-06 03:16:28
你已經在使用完成塊,那是什麼成功塊是 – wattson12 2012-08-06 07:32:53
謝謝你的建議。我試圖在**和** out **塊中設置'NSLog'函數**。 **在**塊中,「NSLog」功能輸出正確。但是在塊的**外**中,相同的'NSLog'函數輸出'(null)'。我很抱歉打擾你,但如果你有任何想法,請告訴我。 – weed 2012-08-06 09:54:55