[英]Pass parse.com cloud backend data from TableView to DetailViewController
I have a problem with my parse backend app. 我的解析后端应用程序有问题。
On Parse I have a Class like this: name (string) , imageFile (File) and help (string). 在Parse上,我有一个这样的类:name(字符串),imageFile(文件)和help(字符串)。
Everything works great except the Images. 除图像外,其他所有功能都很好。 When I tap on a cell, I am pushed to the DetailViewController the 2 Strings appear but the ImageView (PFImageView) is empty. 当我点击一个单元格时,我被推到DetailViewController,出现2个字符串,但是ImageView(PFImageView)为空。 The ImageView does not show my Images. ImageView不显示我的图像。 Maybe there is a problem with passing the image file? 传递图像文件可能有问题吗?
Here is my code: 这是我的代码:
MechanikViewController.h: MechanikViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface MechanikViewController : PFQueryTableViewController
@end
MechanikViewController.m: MechanikViewController.m:
#import "MechanikViewController.h"
#import "MechanikDetailViewController.h"
#import "Mechanik.h"
@interface MechanikViewController ()
@end
@implementation MechanikViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
self.parseClassName = @"Mechanik";
self.textKey = @"name";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = NO;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
if ([self.objects count] == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByAscending:@"name"];
return query;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *simpleTableIdentifier = @"MechanikCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [object objectForKey:@"name"];
return cell;
}
- (void) objectsDidLoad:(NSError *)error
{
[super objectsDidLoad:error];
NSLog(@"error: %@", [error localizedDescription]);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
MechanikDetailViewController *destViewController = segue.destinationViewController;
PFObject *object = [self.objects objectAtIndex:indexPath.row];
Mechanik *mechanik = [[Mechanik alloc] init];
mechanik.name = [object objectForKey:@"name"];
mechanik.imageFile = [object objectForKey:@"imageFile"];
mechanik.help = [object objectForKey:@"help"];
destViewController.mechanik = mechanik;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
MechanikDetailViewController.h: MechanikDetailViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "Mechanik.h"
@interface MechanikDetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet PFImageView *formelImage;
@property (weak, nonatomic) IBOutlet UILabel *helpLabel;
@property (nonatomic, strong) Mechanik *mechanik;
@end
MechanikDetailViewController.m: MechanikDetailViewController.m:
#import "MechanikDetailViewController.h"
@interface MechanikDetailViewController ()
@end
@implementation MechanikDetailViewController
@synthesize formelImage;
@synthesize helpLabel;
@synthesize mechanik;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = mechanik.name;
self.helpLabel.text = mechanik.help;
self.formelImage.file = mechanik.imageFile;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
Mechanik.h: Mechanik.h:
#import <Foundation/Foundation.h>
#import <Parse/Parse.h>
@interface Mechanik : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) PFFile *imageFile;
@property (nonatomic ,strong) NSString *help;
@end
Mechanik.m: Mechanik.m:
#import "Mechanik.h"
@implementation Mechanik
@synthesize name;
@synthesize imageFile;
@synthesize help;
@end
Please help me. 请帮我。
Create a PFObject in DetailViewController 在DetailViewController中创建PFObject
@property (nonatomic, strong)PFObject *object
Pass a PFObject from master to detail 将PFObject从主对象传递到详细信息
PFObject *object = [self.objects objectAtIndex:indexPath.row]; destViewController.object = object;
Set data in ViewDidAppear 在ViewDidAppear中设置数据
pfImageView.imageFile = [object objectForKey:@"imageFile"]; [pfImageView loadInBackground];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.