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

在集合视图控制器中尝试,

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

你错过了这条线。

于 2013-02-06T05:37:14.537 回答
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];
  }
于 2013-02-06T05:46:10.760 回答
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 回答