2013-02-06 70 views
1

從遠程XML檢索數據,我可以在集合視圖中顯示圖像。從這個集合視圖我試圖顯示一個詳細的視圖控制器,如果在集合視圖控制器中單擊圖像,它應該在詳細視圖中顯示圖像。我被困在這裏,我無法顯示詳細視圖控制器。我哪裏錯了?請引導我。如何將圖像從集合視圖傳遞到iphone中的詳細視圖

下面是我收集的視圖控制器,

- (void)viewDidLoad 
    { 
    [super viewDidLoad]; 
    xmlParser = [[MyXMLParser alloc] loadXMLByURL:@"http://MyXml.com/sample.xml"]; 
    myarray = xmlParser.arrayofimages; 
    } 

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
    { 
    return 1; 
    } 

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
    { 
    return [myarray count]; 
    } 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
    { 
    MyCollectionViewCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath]; 
    if (!myCell) { 
     myCell = [[MyCollectionViewCell alloc] initWithFrame:CGRectMake(0,0,myCell.frame.size.width , myCell.frame.size.height)]; 
    } 
    [myCell.tweetImageView setImage:[myarray objectAtIndex:indexPath.row]]; 
    return myCell; 
    } 

- (void)collectionView:(UICollectionViewCell *)collectionView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"MyCell" bundle:[NSBundle mainBundle]]; 
    detailVC.img= [myarray objectAtIndex: indexPath.row]; 
    [self presentViewController:detailVC animated:YES completion:nil]; 
    } 

的DetailView控制器

-(void)viewDidLoad 
    { 
    [super viewDidLoad]; 
    self.imageView.image = self.img; 
    } 
+0

後指定圖像,請確認在「didSelectRowAtIndexPath方法」 –

回答

1

嘗試收集視圖控制器,

[self.navigationController pushViewController:detailVC animated:YES]; 

你已經錯過了這條線。

+0

我又增加了它沒有變化給出的筆尖名。我沒有得到詳細視圖控制器 – Sabarish

1

您沒有呈現您的detailview控制器。你只是分配它。

相反的:

- (void)collectionView:(UICollectionViewCell *)collectionView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"MyCell" bundle:[NSBundle mainBundle]]; 
    detailVC.img= [myarray objectAtIndex: indexPath.row]; 
    } 

檢查:

- (void)collectionView:(UICollectionViewCell *)collectionView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"MyCell" bundle:[NSBundle mainBundle]]; 
    detailVC.img= [myarray objectAtIndex: indexPath.row]; 
    [self presentViewController:detailVC animated:YES completion:nil]; 
    } 
+0

我作爲你的建議添加,但它保持不變。我不能移動到詳細的視圖控制器 – Sabarish

+0

放在斷點的didSelect方法和viewdidload的detailview,並告訴我它是否打 –

+0

新iPhone開發對不起,你能告訴我該怎麼做 – Sabarish

1

試試這個。呈現視圖

DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"MyCell" bundle:[NSBundle mainBundle]]; 
     [self presentViewController:detailVC animated:YES completion:nil]; 
    detailVC.img= [myarray objectAtIndex: indexPath.row]; 
+0

它保持不變,沒有變化 – Sabarish

+0

加載圖像或推送到詳細信息視圖時出現問題嗎? – vishnu

+0

我可以在集合視圖中加載圖像,但是當我單擊圖像以查看詳細信息時,我無法將其從集合視圖控制器推送到詳細視圖控制器 – Sabarish

相關問題