1

リモート XML からデータを取得すると、コレクション ビューで画像を表示できます。このコレクション ビューから、詳細ビュー コントローラーを表示しようとしています。コレクション ビュー コントローラーで画像をクリックすると、画像が詳細ビューで表示されます。詳細ビューコントローラーを表示できない場所で行き詰まりました。どこが間違っていますか?よろしくお願いします。

以下は私のコレクションビューコントローラーです。

- (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];
  }

詳細ビュー コントローラ

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

3 に答える 3

1

これを試して。ビューを提示した後に画像を割り当てる

DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"MyCell" bundle:[NSBundle mainBundle]];
       [self presentViewController:detailVC animated:YES completion:nil];
    detailVC.img= [myarray objectAtIndex: indexPath.row];
于 2013-02-06T06:27:45.683 に答える
1

あなたは詳細ビューコントローラーを提示していません。あなたはそれを割り当てるだけです。

それ以外の:

- (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];
  }
于 2013-02-06T05:46:10.760 に答える
1

Collection View Controllerで試してください。

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

あなたはこの行を見逃していました。

于 2013-02-06T05:37:14.537 に答える