2014-01-12 68 views
1

我迷路了segue。我試圖通過this tutorial傳遞通過segue,PFObject崩潰Parse.com

一切正常,但只有一行寫我錯誤,我不知道如何解決它。 圖像的錯誤:

TableViewController.h

#import <UIKit/UIKit.h> 
#import "Parse/Parse.h" 
#import "CustomCell.h" 
#import "DetailViewController.h" 

@interface TableViewController : UITableViewController <UITableViewDelegate,UISearchDisplayDelegate, UISearchBarDelegate> { 

    NSArray *colorsArray; 
    NSArray *searchResults; 

} 

@property (strong, nonatomic) IBOutlet UITableView *colorsTable; 
@property (strong, nonatomic) IBOutlet UISearchBar *searchBar; 
@property (strong, nonatomic) IBOutlet UISearchDisplayController *searchBarController; 


@end 

TableViewController.m

#import "TableViewController.h" 
#import "CustomCell.h" 
#import "DetailViewController.h" 


@interface TableViewController(){ 
} 



@end 
@implementation TableViewController 


@synthesize colorsTable; 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ if ([segue.identifier isEqualToString:@"displayDetail"]){ 


     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     PFObject *object = [self.objects objectAtIndex:indexPath.row]; 



     UINavigationController *nav = [segue destinationViewController]; 
     DetailViewController *detailViewController = (DetailViewController *) nav.topViewController; 
     detailViewController.exam = object; 
    } 
} 



- (void) retrieveFromParse { 

    PFQuery *retrieveColors = [PFQuery queryWithClassName:@"Hracky1"]; 
    [retrieveColors findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (!error) { 
      colorsArray= [[NSArray alloc] initWithArray:objects]; 
     } 
     [colorsTable reloadData]; 

    }]; 
    [self.colorsTable reloadData]; 
    [self.refreshControl endRefreshing]; 
} 

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


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self performSelector:@selector(retrieveFromParse)]; 

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; 

    self.refreshControl = refreshControl; 

    [refreshControl addTarget:self action:@selector(retrieveFromParse) forControlEvents:UIControlEventValueChanged]; 

} 

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

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return colorsArray.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"colorsCell"; 

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    PFObject *tempObject = [colorsArray objectAtIndex:indexPath.row];; 



    [cell.imageview setFile: [tempObject objectForKey:@"ImageURL"]]; 


    [cell.imageview loadInBackground]; 


    cell.cellTitle.text = [tempObject objectForKey:@"cellTitle"]; 
    cell.cellDescript.text = [tempObject objectForKey:@"cellDescript"]; 



    return cell; 
} 



@end 

DetailedViewController.h

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

@interface DetailViewController : UIViewController <UITextViewDelegate> 

@property (nonatomic, strong) PFObject *exam; 
@property (nonatomic, strong) IBOutlet UITextView *descriptext; 
@end 

DetailViewcontrolled.m

#import "DetailViewController.h" 
#import "Parse/Parse.h" 
#import "TableViewController.h" 

@interface DetailViewController() 

@end 

@implementation DetailViewController 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad];{ 

    self.descriptext.text = [self.exam objectForKey:@"TextView"]; 
    } 

} 




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

@end 

回答

2

從我從你的代碼讀出那是因爲你使用的是正常的UITableViewController。爲了能夠訪問屬性「self.objects」,你必須使用稱爲「PFTableViewController」的Parse的子類UITableViewController。他們已經包括了財產「對象」。

我可以推薦這個教程獲取的PFTableViewController

http://www.appcoda.com/ios-programming-app-backend-parse/

的理解。如果你想讓它沒有PFTableView工作,你可以做到以下幾點: 我可以看到你有一個名爲陣列colorsArray,並將Parse對象添加到該數組中。的

所以不是這樣做:

PFObject *對象= [self.objects objectAtIndex:indexPath.row];

可以做到這一點:

PFObject *對象= [colorsArray objectAtIndex:indexPath.row];

我希望它適合你!

+0

謝謝!現在我終於完全明白了一切。 – Milan1111

0

隨着做這這裏另一個答案已經建議的教程,也許你不應該通過PFObject本身...

圖出來,任何文字你想在您的詳細視圖控制器,以顯示查詢,檢索它在表視圖控制器中,然後只傳遞它(而不是整個PFObject)。

+0

謝謝你的一切,現在完全明白解析。無論如何,我必須重新制作我的所有項目,因爲我是在正常的基礎上做的,而不是Parse。謝謝 – Milan1111