從遠程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;
}
後指定圖像,請確認在「didSelectRowAtIndexPath方法」 –