这是我在 Parse 论坛上提出的一个问题,过去 3 天我没有收到他们的任何回复。因此我在这里发帖。
你好,
我有一个 PFQueryTableViewController 并且表格有带有图像和不同标签的自定义单元格。此表在选择行时导航到另一个 DetailViewController。DetailViewController 需要在其视图中显示图像,我们从查询中获取到 PFQueryTableViewController 中的 Parse 数据库。我如何做到这一点?
表视图控制器.M
@interface TableViewController ()
@end
NSMutableArray* detailObjects;
DetObj* clickedObj;
@implementation TableViewController
- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];
// This method is called every time objects are loaded from Parse via the PFQuery
for (PFObject* object in self.objects)
{
DetailObj* obj = [[DetailObj alloc ] init ];
[obj setDetName:[object objectForKey:@"detName"]];
[mov setDetImage:[object objectForKey:@"detImage"]];
[detailObjects addObject:obj];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *CellIdentifier = @"upCell";
customBigTableCell *cell = (customBigTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[customBigTableCell alloc] init];
}
cell.name.text = [object objectForKey:@"detName"];
cell.image.file = [object objectForKey:@"detImage"];
//this is essential for loading the image from the database
[cell.image loadInBackground];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
newDetailController* newController = [storyboard instantiateViewControllerWithIdentifier:@"Detail"];
clickedObj = [[DetObj alloc] init];
NSIndexPath* path = [self.tableView indexPathForSelectedRow];
clickedObj = [detailObjects objectAtIndex:path.row];
[newController setDetInfo:clickedObj];
[[self navigationController] pushViewController:newController animated:YES];
}
我已尝试在 DetailViewController 中使用如下所述的 PFImageView。detailInfo 是从前面的 PFQueryTableViewController 传递过来的对象。
newDetailController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
PFImageView* detImage = [[PFImageView alloc] initWithFrame:CGRectMake(300,0,320,150)];
PFFile* file = detailInfo.fullImage.file;
detImage.file = file;
[detImage loadInBackground];
[self.view addSubview:detImage];
}
但我有这个错误。
reason: '-[PFFile file]: unrecognized selector sent to instance
我不想再次查询数据库来获取我在前一个控制器中已经获得的信息。
谢谢安德鲁