HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – setObjectForKey:exception:object不能为nil大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Parse和 Xcode构建应用程序.使用Parse PFTableView时,我收到错误

我知道我没有在我的代码中设置密钥,但我不知道在哪里以及如何解决它.

#import "TableViewController.h"
#import <Parse/Parse.h>

@interface TableViewController ()

@end

@implementation TableViewController

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


- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve SELEction between presentations.
    // self.cleaRSSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    self.parentViewController.view.BACkgroundColor = [UIColor colorWithPatternImage:[UIImage imagenamed:@"red_bokeh.png"]];
    self.tableView.BACkgroundColor = [UIColor clearColor];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

#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
}

- (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 = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reusEIDentifier:CellIdentifier];
    }

    // Configure the cell
    cell.textLabel.text = object[@"text"];
    cell.detailTextLabel.text = [NSString StringWithFormat:@"Priority: %@",object[@"priority"]];

    return cell;
}
- (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView didSELEctRowATindexPath:indexPath];
}


@end

这是TableViewController.h:

#import <UIKit/UIKit.h>

@interface TableViewController : PFQueryTableViewController

@end

解决方法

我按照这个 Parse.com/help解决了这个问题

我只是将方法从initWithStyle更改为initWithCoder.

- (id)initWithCoder:(NSCoder *)aDecoder
    {
    self = [super initWithCoder:aDecoder];
    if (self) {

        // The className to query on
        self.parseClassName = kPAPPhotoClassKey;

        // 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 = 10;

    }
    return self;
}

大佬总结

以上是大佬教程为你收集整理的ios – setObjectForKey:exception:object不能为nil全部内容,希望文章能够帮你解决ios – setObjectForKey:exception:object不能为nil所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。