2014-02-22 4 views
0

PFQueryTableViewController라는 구문 분석을 사용하여 클래스를 사용자 정의하려고합니다. 그래도 내 세포를 사용자 정의하고 싶지는 않습니다.UITableViewController는 사용자 정의하지 않습니다.

- (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은 IB를 사용하여 레이블을 추가하는 UITableViewCell의 하위 클래스입니다. 내 하위 클래스 PFQueryTableViewController에 대한 TableView도 IB를 통해 생성됩니다.

답변

1

xib가 아직로드되지 않은 초기화 방법 대신 "viewDidLoad"에서 사용자 지정을 수행해야합니다.

0

잘못하고 있습니다. 번들에서 셀을로드해야합니다.

[NSBundle mainBundle] loadNibNamed : @ "CustomCell"owner : self options : nil];

cellForRowAtIndexPath 또는 init 및 awake from 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; 
} 
관련 문제