UITableViewController不会自定义

时间:2014-02-22 21:42:24

标签: iphone objective-c parsing uitableview

我正在尝试使用名为PFQueryTableViewController的Parse自定义类。但它似乎并不想自定义我的细胞:

-  (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithClassName:@"UserPhoto"];
self = [super initWithCoder:aDecoder];

if (self) {
    // Custom the table

    // The className to query on
    self.parseClassName = @"UserPhoto";

    // The key of the PFObject to display in the label of the default cell style
    self.textKey = @"title";   
    // Whether the built-in pull-to-refresh is enabled
    self.pullToRefreshEnabled = YES;

    // Whether the built-in pagination is enabled
    self.paginationEnabled = YES;

    // The number of objects to show per page
    self.objectsPerPage = 25;
}
return self;
}



- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    [self.tableView registerNib:[UINib nibWithNibName:@"FeedCustomCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FeedCustom"];
}

#pragma mark - Parse

- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];

// This method is called every time objects are loaded from Parse via the PFQuery
}

- (void)objectsWillLoad {
[super objectsWillLoad];

// This method is called before a PFQuery is fired to get more objects
NSLog(@"Done");
}


// Override to customize what kind of query to perform on the class. The default is to     query for
// all objects ordered by createdAt descending.
- (PFQuery *)queryForTable {

PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if ([self.objects count] == 0) {
    query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}

[query orderByDescending:@"createdAt"];

NSLog(@"%@", query);
return query;

}



// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the object.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {


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

// Configure the cell
cell.caption.text = [object objectForKey:@"title"];


cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;


return cell;

}

有什么想法吗? FeedCustomCell只是UITableViewCell的子类,它使用IB添加标签。我的子类PFQueryTableViewController的TableView也是通过IB创建的。

2 个答案:

答案 0 :(得分:1)

您应该在“viewDidLoad”中进行自定义,而不是在尚未加载xib的init方法中进行自定义。

答案 1 :(得分:0)

你做错了。您需要使用

从bundle中加载单元格
  

[NSBundle mainBundle] loadNibNamed:@“CustomCell”所有者:自选:nil];

在您的cellForRowAtIndexPath中或在您的init中并从nib方法唤醒。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FeedCustomCell *cell = (FeedCustomCell*)[tableView dequeueReusableCellWithIdentifier:@"BDCustomCell"];

    if (cell == nil) {
        // Load the top-level objects from the custom cell XIB.
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"FeedCustomCellXib" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        cell = [topLevelObjects objectAtIndex:0];
    }

    return cell;
}