0

我不明白这一点,但是当我尝试启动我的应用程序时,总是会出错。有人能帮我吗?我认为这可能是 TableeViewController.m 中的内容。但我不确定。谢谢

表格单元格.h

#import < Parse/Parse.h >

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

@end

表格单元格.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

表视图.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
4

1 回答 1

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/

祝你好运!

于 2014-01-13T00:12:21.523 回答