2014-01-12 24 views
0

我不明白這個,但總是當我嘗試啓動我的應用程序,我得到錯誤。 有人可以幫我嗎?我想這可能是TableeViewController.m中的一些東西。但我不確定。 感謝PFQueryTableViewController與自定義單元格崩潰時發射

TableCell.h

#import <Parse/Parse.h> 

@interface TableCell : PFTableViewCell 
@property (strong, nonatomic) IBOutlet UILabel *cellTitle; 
@property (strong, nonatomic) IBOutlet UILabel *cellDescript; 

@end 

TableCell.m

#import "TableCell.h" 

@implementation TableCell 
@synthesize cellTitle; 
@synthesize cellDescript; 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

/* 
// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
} 
*/ 

@end 

TableeView.h

#import <Parse/Parse.h> 
#import "TableCell.h" 
#import "DetailViewController.h" 

@interface TableeViewController : PFQueryTableViewController { 

    NSArray *colorsArray; 

} 

@property (strong, nonatomic) IBOutlet UITableView *colorsTable; 


@end 

TableeViewController.m

#import "TableeViewController.h" 
#import "TableCell.h" 
#import "DetailViewController.h" 

@interface TableeViewController() 

     @end 

     @implementation TableeViewController @synthesize colorsTable; 


     - (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)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
      if (self) { 
      } 
      return self; } 

     - (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; } 


     - (void)viewDidLoad { 
      [super viewDidLoad]; 

      [self performSelector:@selector(retrieveFromParse)]; 
      } 

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

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject 
    *)object { 

      TableCell *cell = (TableCell *)[self.tableView dequeueReusableCellWithIdentifier:@"colorsCell" 
     forIndexPath:indexPath]; 

      NSString * cellTitle = [object objectForKey:@"cellTitle"]; 
      NSString * cellDescript = [object objectForKey:@"cellDescript"]; 

      cell.cellTitle.text = cellTitle; 
      cell.cellDescript.text = cellDescript; 

     return cell; } 

     @end 
+0

此鏈接幫助我解決了這個問題。 http://stackoverflow.com/questions/20963486/custom-cell-not-displaying-pfimageview?rq=1 – Milan1111

回答

0

我已經解決了這個問題。 如果你有同樣的問題。看看這個問題。 Here

0

它看起來像你已經劃分了PFTableViewCell並創建了屬性「cellTitle」和「cellDescription」,但是你還沒有初始化並將它們添加到TableCell中。 如果您沒有對PFTableViewCell進行任何更改,似乎沒有理由繼承PFTableViewCell。實際上你可以使用普通的UITableViewCell。

所以,刪除 「TableCell的」,並通過使用一個UITableViewCell創建細胞:

static NSString *simpleTableIdentifier = @"ColorsCell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier]; 
} 

然後你就可以做這個訪問屬性 「爲textLabel」 和 「detailTextLabel」:

cell.textLabel.text = [object objectForKey:@"cellTitle"]; 
cell.detailTextLabel.text = [object objectForKey:@"cellDescript"]; 

按照本教程從頭到尾,你會到達那裏:

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

祝你好運!

+0

你能解釋我reuseIdentifier的用法:simpleTableIdentifier?因爲它是在說我未申報的標識符。謝謝 – Milan1111

+0

看到我編輯的評論。 simpleTableIdentifier基本上是一個定義CellIdentifier的NSString。 – fisher

+0

感謝您的幫助,但它並沒有爲我工作。我修好了它。不管怎麼說,多謝拉。 – Milan1111

相關問題