2016-08-28 42 views
0

我正在使用數據任務通過JSON文件從外部服務器顯示文本數據。這是工作很好 和我使用AFNetworking的文件#import "UIImageView+AFNetworking.h"從上面下載圖像提取數據在Tableview的單元格聲明它也工作得很好。 但選擇行時通過Segue公司通過選擇的行圖像到它給錯誤的另一個視圖控制器,通過Segue將緩存映像傳遞給DetailViewController

這裏是我的泰伯維的單元代碼,這是非常精細&顯示文本&圖像數據

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"maincell" forIndexPath:indexPath]; 

    Categories * CategoryObject; 
    CategoryObject = [categoryArray objectAtIndex:indexPath.row]; 
    cell.textLabel.text = CategoryObject.categoryTitle; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    // Configure the cell Image... 

    NSURL *url = [NSURL URLWithString:CategoryObject.categoryImage]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    UIImage *placeholderImage = [UIImage imageNamed:@"placeholder"]; 
    __weak UITableViewCell *weakCell = cell; 
    [cell.imageView setImageWithURLRequest:request placeholderImage:placeholderImage success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
     weakCell.imageView.image = image; 
     [weakCell setNeedsLayout]; 
    } failure:nil]; 

    return cell; 
} 

現在看看Segue公司代碼給錯誤

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"showAnotherView"]) { 

     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     DetailImageViewController *destViewController = segue.destinationViewController; 
     destViewController.imageName = [ UIImageView objectAtIndex:indexPath.row.image]; 

    } 
} 

我的代碼給錯誤

在代碼的最後一行的選擇objectAtIndex:

沒有已知的類方法

destViewController.imageName = [ UIImageView objectAtIndex:indexPath.row.image]; 

我要完成的事情是解決這一錯誤,並通過它下載上述緩存的圖片通過AFNetworking並將該圖像傳遞給下一個視圖控制器。任何人都可以幫我嗎?

+0

'objectAtIndex'適用於數組。 'UIImageView'不是一個數組。 'indexPath.row'是一個數字。數字沒有「圖片」屬性。換句話說,那行代碼非常錯誤,我無法猜測它應該訪問什麼值。 –

+0

@philiip Mills,是的你是對的,因此我需要知道在這行代碼中我們應該傳遞哪個值,而我通過上面的AFNetworking代碼提取了圖像。我在評論中聲明'//配置單元格圖像...' –

回答

1

看着你的代碼,好像你正在訪問objectAtIndex:方法UIImageView,它沒有這個方法,除非你的類別擴展爲UIImageView。如果你要處理原始選擇,它應該是這樣的,

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"showAnotherView"]) 
    { 
     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath]; 
     DetailImageViewController *destViewController = segue.destinationViewController; 
     destViewController.imageName = Cell.imageView.image; 

    } 
} 

希望得到這個幫助。

+0

無法清除,請您用您的建議代碼解決問題? –

+1

這次你的代碼完全適合,但是編譯器給我提示改變它卻有一個小小的錯誤。那就是在最後一行的'Cell.imageView.image;'正確的位置是'cell.imageView.image;'我的意思是有一個小的'c'而不是'cell'的大寫'c'。 非常感謝,你解決了我的應用程序的一個主要問題。 –