【发布时间】:2013-05-19 03:03:33
【问题描述】:
我有一个 IOS 应用程序,它使用 RestKit 将 json 格式的数据从服务器拉入 CoreData 实体。实体的一些属性有助于使用每个单元格的图像和标题填充集合视图。
当一个单元格被选中时,我试图从集合视图移动到详细视图。 CoreData 实体有一个“摘要”属性,我想在详细视图中与图像一起显示。
我知道我可以通过prepareForSegue 方法传递数据。但是我不确定如何指定要传递的图像和摘要数据。
也许传递图像和摘要不是正确的方法?我应该将managedObjectContext 传递给详细视图控制器并从那里获取结果吗?
这是我的 CollectionView 的填充方式。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
MyNewsCollectionViewCell *cell = (MyNewsCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSURL *photoURL = [NSURL URLWithString:(NSString *) [object valueForKey:@"imageUrl"]];
NSData *photoData = [NSData dataWithContentsOfURL:photoURL];
[cell.cellimg setImage:[[UIImage alloc] initWithData:photoData]];
[cell.title setText:[object valueForKey:@"title"]];
return cell;
这里是prepareForSegue 方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"newsDetail"]) {
NewsDetailViewController *vc =[segue destinationViewController];
vc.newsDetailImageView = //How do I designate the image from the cell I selected???
vc.newsDetailText = //How do I designate the text from the cell I selected???
}
}
这显然是一个初学者的问题....任何帮助将不胜感激。鉴于我是初学者,基本示例代码真的很有帮助!
【问题讨论】:
标签: iphone ios core-data segue managedobjectcontext