Search code examples
parse-platformpfquerypfquerytableviewcontrolle

[Error]: bad characters in classname - PFQueryTableViewController


Hi I've been trying to test the functionality of the Parse PFQueryTableViewController... however keep receiving the following error:

[Error]: bad characters in classname: (null) (Code: 103, Version: 1.8.0)

I'm using the standard code from the Parse website for doing this and attempting to load the tableviewcontroller from my Pase class: Categories i.e:

- (instancetype)initWithStyle:(UITableViewStyle)style {
    self = [super initWithStyle:style];
    if (self) { // This table displays items in the Todo class
        self.parseClassName = @"Categories";
        self.pullToRefreshEnabled = YES;
        self.paginationEnabled = YES;
        self.objectsPerPage = 25;
    }
    return self;
}

- (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"];

    return query;
}



- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
                        object:(PFObject *)object {
    static NSString *cellIdentifier = @"categoryCell";

    PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:cellIdentifier];}

    // Configure the cell to show todo item with a priority at the bottom

    cell.textLabel.text = object[@"Category"];
    cell.detailTextLabel.text = object[@"Sequence"];

    return cell;
}

Any help would be great fully received, thanks.


Solution

  • There is a problem when creating the parse-supplied vc using interface builder: IB view controllers are initialized with initWithCoder:, not initWithStyle.

    One way to cover either kind of initializer is to factor the custom code and implement both, like this:

    - (void)customInit {
        self.parseClassName = @"Categories";
        self.pullToRefreshEnabled = YES;
        self.paginationEnabled = YES;
        self.objectsPerPage = 25;
    }
    
    - (id)initWithStyle:(UITableViewStyle)style {
        self = [super initWithStyle:style];
        if (self) {
            [self customInit];
        }
        return self;
    }
    
    - (id)initWithCoder:(NSCoder *)aDecoder {
        self = [super initWithCoder:aDecoder];
        if (self) {
            [self customInit];
        }
        return self;
    }