启动时自定义单元格崩溃的PFQueryTableViewController

时间:2014-01-12 22:54:12

标签: ios objective-c parse-platform custom-cell pfquery

我不明白这一点,但总是当我尝试启动我的应用时,我收到错误。 有人能帮我吗?我认为这可能是TableeViewController.m中的一些东西。但我不确定。 感谢

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

1 个答案:

答案 0 :(得分:0)

看起来您已经将PFTableViewCell子类化并创建了属性“cellTitle”和“cellDescription”,但您尚未初始化并将它们添加到TableCell中。 如果你没有对它进行任何更改,似乎没有理由继承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/

祝你好运!