财产"对象"在类型的对象上找不到

时间:2014-03-20 18:51:18

标签: ios objective-c uitableview uistoryboardsegue detailview

我对bookstableview.m segue有疑问。如果你看到PFObject * object = [self.objects objectatindex.indexPath.row]的地方,那么"对象"说"在类型' BooksTableViewController的对象上找不到属性对象'。"

这是代码的其余部分:Bookstableview.m

#import "BooksTableViewController.h"
#import "BookDetailViewController.m"

@interface BooksTableViewController ()

@end

@implementation BooksTableViewController

@synthesize bookstableview;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self performSelector:@selector(RetrieveDatafromParse)];
}

-(void) RetrieveDatafromParse {
    PFQuery * getbooks = [PFQuery queryWithClassName:@"BooksTableView"];

    [getbooks findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if(!error) {
            Booksarray =[[NSArray alloc] initWithArray: objects];
        }
        [bookstableview reloadData];
        NSLog(@"%@",objects);
    }];    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:     (NSInteger)section
{    
    return Booksarray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"Cell";
    UITableViewCell * cell = [bookstableview    dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell ==nil) {
        cell = [[ UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }
    PFObject * tempObject = [Booksarray objectAtIndex:indexPath.row];
    cell.textLabel.text = [tempObject objectForKey:@"Books"];
    cell.detailTextLabel.text= [tempObject objectForKey:@"Code"];

    return cell;
}


- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

    [self performSegueWithIdentifier:@"booksseg" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([[segue identifier] isEqualToString:@"ShowDetails"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        PFObject * object = [self.objects objectAtIndex:indexPath.row];
        PFFile *file = [object objectForKey:@"BooksTableView"];
        [[segue destinationViewController] setFile:file];
    }
}
@end

bookstableview.h

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

@interface BooksTableViewController : UITableViewController <UITableViewDelegate >
{
    NSArray * Booksarray;
}
@property (strong, nonatomic) IBOutlet UITableView *bookstableview;

@end

Booksdetailview.h

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "BooksTableViewController.h"
@interface BookDetailViewController : UIViewController {

}
@property (weak, nonatomic) IBOutlet UIImageView *BookImage;
@property (weak, nonatomic) IBOutlet UILabel *bookTitle;
@property (weak, nonatomic) IBOutlet UILabel *bookDesc;
@property (weak,nonatomic) PFObject *file;
@end

1 个答案:

答案 0 :(得分:0)

self.objects替换为Booksarray

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([[segue identifier] isEqualToString:@"ShowDetails"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        PFObject * object = [Booksarray objectAtIndex:indexPath.row];
        PFFile *file = [object objectForKey:@"BooksTableView"];
        [[segue destinationViewController] setFile:file];
    }
}

另外:通常,只有类名称大写,而变量和方法以小写字母开头,因此_booksArray将是变量的更合适的名称。有助于避免混淆并防止类/变量名称重叠。