0

我的解析后端应用程序有问题。

在 Parse 中,我有一个这样的类:名称(字符串)、图像文件(文件)和帮助(字符串)。

除了图像,一切都很好。当我点击一个单元格时,我被推送到 DetailViewController 出现 2 个字符串,但 ImageView (PFImageView) 为空。ImageView 不显示我的图像。也许传递图像文件有问题?

这是我的代码:

机械视图控制器.h:

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface MechanikViewController : PFQueryTableViewController

@end

机械视图控制器.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:

#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:

#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

机械师.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

机械师.m:

#import "Mechanik.h"

@implementation Mechanik

@synthesize name;
@synthesize imageFile;
@synthesize help;

@end

请帮我。

4

1 回答 1

0
  • 在 DetailViewController 中创建一个 PFObject

    @property (nonatomic, strong)PFObject *object
    
  • 将 PFObject 从 master 传递到 detail

    PFObject *object = [self.objects objectAtIndex:indexPath.row];
    destViewController.object = object;
    
  • 在 ViewDidAppear 中设置数据

    pfImageView.imageFile = [object objectForKey:@"imageFile"];
    [pfImageView loadInBackground];
    
于 2014-01-07T01:31:21.910 回答