PFQueryTableViewController does not show user cells

I have a subclass of PFQueryTableViewController which I am trying to show as a container (as a subtitle). My problem is that I cannot get user cells to appear in a table. I checked the following with debugging:

  • The table view is added to the parent view.
  • Tableview is a PFQueryTableView controller, as it includes default updates
  • PFQuery returns the correct number of objects
  • The CellForRowAtIndexPath method is called and repeated through the correct number of times.
  • The correct data from Parse is transferred to different labels in the cells
  • These labels are connected via IBOulets in my subclass of UITableViewCell. When I try to access shortcuts, it works correctly when it accesses a subclass and label

I have everything that works here correctly, except that it is actually a box! What am I missing?

This is my cellForRowAtIndexPath code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{ static NSString *CellIdentifier = @"RoundCell"; RoundCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; if (cell == nil) { cell = [[RoundCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // get string values from Parse NSString * teeString =[object objectForKey:@"roundTee"]; NSString* courseString = [object objectForKey:@"roundCourse"]; NSString * courseString2 = [[courseString stringByAppendingString:@" - "]stringByAppendingString:teeString]; NSString * dateString = [object objectForKey:@"roundDate"]; NSString * scoreString = [object objectForKey:@"roundScore"]; NSString * differentialString = [object objectForKey:@"roundDifferential"]; cell.courseNameCell.text = courseString2; cell.dateCell.text = dateString; cell.scoreCell.text= scoreString; cell.differentialCell.text=differentialString; return cell; } 
0
parse.com pfquery
source share
3 answers

The correct method is to call the custom cell in cellForRowAtIndexPath.

Check out two main things:

1. on the storyboard and click on a cell in the attribute inspector, check that the cell has the correct identifier

enter image description here

2. set cellForRowAtIndexPath like this:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{ CustomCell *cell = (CustomCell * )[self.tableView dequeueReusableCellWithIdentifier:@"YOUR CELL NAME" forIndexPath:indexPath]; 

So in your case try:

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{ CustomCell *cell = (CustomCell * )[self.tableView dequeueReusableCellWithIdentifier:@"YOUR CELL NAME" forIndexPath:indexPath]; NSString * teeString =[object objectForKey:@"roundTee"]; NSString* courseString = [object objectForKey:@"roundCourse"]; NSString * courseString2 = [[courseString stringByAppendingString:@" - "]stringByAppendingString:teeString]; NSString * dateString = [object objectForKey:@"roundDate"]; NSString * scoreString = [object objectForKey:@"roundScore"]; NSString * differentialString = [object objectForKey:@"roundDifferential"]; cell.courseNameCell.text = courseString2; cell.dateCell.text = dateString; cell.scoreCell.text= scoreString; cell.differentialCell.text=differentialString; return cell; } 

Remember to import the custom cell subclass into File.m

 #import "YourCustomCell.h" 

and set the cell in the identity inspector

enter image description here

+2
source share

If you created your UITableView cell in XIB (which sounds like you), you cannot use the alloc init paradigm to initialize your object. You should use:

 cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCellXibFile" owner:nil options:nil] objectAtIndex:0] 
0
source share

Swift Version (up to 1.2):

 import UIKit class JPUsersTableViewController: PFQueryTableViewController { override init!(style: UITableViewStyle, className: String!) { super.init(style: style, className: className) textKey = "username" pullToRefreshEnabled = true paginationEnabled = true objectsPerPage = 25 } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override func viewDidLoad() { super.viewDidLoad() title = "Users" tableView.registerClass(PFTableViewCell.self, forCellReuseIdentifier: kTableViewCellIdentifier) tableView.separatorInset.right = tableView.separatorInset.left tableView.tableFooterView = UIView(frame: CGRectZero) view.backgroundColor = kbackgroundColor let returnIcon = UIBarButtonItem(image: kNavBarReturnIcon, style: .Plain, target: navigationController, action: "popViewControllerAnimated:") returnIcon.tintColor = kToolbarIconColor navigationItem.leftBarButtonItem = returnIcon tableView.reloadData() addPullToRefresh() } override func queryForTable() -> PFQuery! { let query = PFUser.query() query.whereKey("username", notEqualTo: PFUser.currentUser().username) query.orderByAscending("username") //if network cannot find any data, go to cached (local disk data) if (self.objects.count == 0){ query.cachePolicy = kPFCachePolicyCacheThenNetwork } return query } // MARK: - Navigation override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PFTableViewCell cell.textLabel?.text = object["username"] as? String if let profileImage = object["profileImage"] as? PFFile { cell.imageView.file = profileImage } else { cell.imageView.image = kProfileDefaultProfileImage } cell.textLabel?.font = UIFont(name: kStandardFontName, size: kStandardFontSize) cell.textLabel?.textColor = UIColor.whiteColor() cell.backgroundColor = kbackgroundColor return cell } override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return 50 } } 
0
source share

All Articles