我有一个工作应用程序,可以让用户查看工作。 Jobs 是我的 Parse 后端中的一个类。我想创建一个收藏夹选项卡,用户可以在其中标记某些作业。
我在我的用户类中创建了一个关系列,将其引用到我的工作类。
但是,当用户点击将作业设为最爱时,我遇到了这个问题:[错误]:无法将非指针添加到关系(代码:111,版本:1.7.5)
我觉得我的 PFRelation 编码是正确的。我研究了这个错误,但似乎找不到与我的问题相关的任何主题。我一定是在某个地方犯了错误,但是
@interface JobDetailViewController ()
@end
@implementation JobDetailViewController
@synthesize jobPhoto;
@synthesize RotationLabel;
@synthesize QualificationsTextView;
@synthesize Job_DescriptionTextView;
@synthesize TypeLabel;
@synthesize LocationLabel;
@synthesize ClearanceLabel;
@synthesize PositionLabel;
@synthesize job;
@synthesize POC;
@synthesize Email;
@synthesize Phone;
@synthesize Apply;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[_Scroller setScrollEnabled:YES];
[_Scroller setContentSize:CGSizeMake(320, 2200)];
[self dismissKeyboard];
self.PositionLabel.text = job.position;
self.RotationLabel.text = job.rotation;
self.LocationLabel.text = job.location;
self.TypeLabel.text = job.type;
self.ClearanceLabel.text = job.clearance;
jobPhoto.file = (PFFile *)job.imageFile;
[jobPhoto loadInBackground];
NSMutableString *pocText = [NSMutableString string];
for (NSString* poc in job.poc) {
[pocText appendFormat:@"%@\n", poc];
}
self.POC.text = pocText;
NSMutableString *emailText = [NSMutableString string];
for (NSString* email in job.email) {
[emailText appendFormat:@"%@\n", email];
}
self.Email.text = emailText;
NSMutableString *phoneText = [NSMutableString string];
for (NSString* phone in job.phone) {
[phoneText appendFormat:@"%@\n", phone];
}
self.Phone.text = phoneText;
NSMutableString *applyText = [NSMutableString string];
for (NSString* apply in job.apply) {
[applyText appendFormat:@"%@\n", apply];
}
self.Apply.text = applyText;
NSMutableString *qualificationsText = [NSMutableString string];
for (NSString* qualifications in job.qualifications) {
[qualificationsText appendFormat:@"%@\n", qualifications];
}
self.QualificationsTextView.text = qualificationsText;
NSMutableString *job_descriptionText = [NSMutableString string];
for (NSString* job_description in job.job_description) {
[job_descriptionText appendFormat:@"%@\n", job_description];
}
self.Job_DescriptionTextView.text = job_descriptionText;
}
- (IBAction)favoriteButtonAction:(id)sender {
PFObject *jobs = [PFObject objectWithClassName:@"Jobs"];
PFUser *user = [PFUser currentUser];
PFRelation *relation = [user relationForKey:@"Favorites"];
[relation addObject:jobs];
[user saveInBackground];
}
- (void)viewDidUnload
{
[self setJobPhoto:nil];
[self setPositionLabel:nil];
[self setRotationLabel:nil];
[self setLocationLabel:nil];
[self setTypeLabel:nil];
[self setQualificationsTextView:nil];
[self setJob_DescriptionTextView:nil];
[self setPOC: nil];
[self setPhone:nil];
[self setEmail:nil];
[self setApply:nil];
[self dismissKeyboard];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(void) dismissKeyboard {
[Email resignFirstResponder];
[POC resignFirstResponder];
[Phone resignFirstResponder];
[Job_DescriptionTextView resignFirstResponder];
[QualificationsTextView resignFirstResponder];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void) favoriteSuccess {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Added job to Favorites!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
- (void) favoriteFailed {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:@"Error occurred while adding to Favorites!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
@end
在 JobDetailViewController 之前填充作业的 JobListViewController:
#import "JobDetailViewController.h"
#import "JobListViewController.h"
#import "Job.h"
#import "SearchedResultCell.h"
#import <Parse/Parse.h>
@interface JobListViewController () <UISearchDisplayDelegate, UISearchBarDelegate> {
}
@property (nonatomic, weak) IBOutlet UISearchBar *searchedBar;
@property (nonatomic, strong) NSString *mainTitle;
@property (nonatomic, strong) NSString *subTitle;
@property (nonatomic, assign) BOOL canSearch;
@end
@interface JobListViewController ()
@end
@implementation JobListViewController
{}
@synthesize searchedBar;
@synthesize mainTitle;
@synthesize subTitle;
@synthesize canSearch;
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
// Custom the table
// The className to query on
self.parseClassName = @"Jobs";
// The key of the PFObject to display in the label of the default cell style
self.textKey = @"Position";
// 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 = 20;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.canSearch = 0;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)objectsWillLoad {
[super objectsWillLoad];
// This method is called before a PFQuery is fired to get more objects
}
- (PFQuery *)queryForTable
{
PFQuery *query1 = [PFQuery queryWithClassName:@"Jobs"];
NSString *searchThis = [searchedBar.text capitalizedString];
[query1 whereKey:@"Position" containsString:searchThis];
PFQuery *query2 = [PFQuery queryWithClassName:@"Jobs"];
[query2 whereKey:@"Type" containsString:searchThis];
PFQuery *query = [PFQuery orQueryWithSubqueries:@[query1,query2]];
[query orderByDescending:@"createdAt"];
if (self.pullToRefreshEnabled) {
query.cachePolicy = kPFCachePolicyNetworkOnly;
}
// 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.
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object: (PFObject *)object
{
static NSString *simpleTableIdentifier = @"JobCell";
static NSString *pimpleTableIdentifier = @"JobCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
SearchedResultCell *bell = [self.tableView dequeueReusableCellWithIdentifier:pimpleTableIdentifier];
if (bell == nil) {
bell = [[SearchedResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pimpleTableIdentifier];
}
[self configureSearchResult:bell atIndexPath:indexPath object:object];
}
// Configure the cell
PFFile *thumbnail = [object objectForKey:@"imageFile"];
PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
thumbnailImageView.image = [UIImage imageNamed:@"AppIcon.png"];
thumbnailImageView.file = thumbnail;
[thumbnailImageView loadInBackground];
UILabel *positionLabel = (UILabel*) [cell viewWithTag:101];
positionLabel.text = [object objectForKey:@"Position"];
UILabel *rotationLabel = (UILabel*) [cell viewWithTag:102];
rotationLabel.text = [object objectForKey:@"Rotation"];
UILabel *locationLabel = (UILabel*) [cell viewWithTag:103];
locationLabel.text = [object objectForKey:@"Location"];
UILabel *typeLabel = (UILabel*) [cell viewWithTag:104];
typeLabel.text = [object objectForKey:@"Type"];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showJobDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Job *job = [[Job alloc] init];
JobDetailViewController *destViewController = segue.destinationViewController;
PFObject *object = [self.objects objectAtIndex:indexPath.row];
job.position = [object objectForKey:@"Position"];
job.poc = [object objectForKey:@"POC"];
job.email = [object objectForKey:@"Email"];
job.phone = [object objectForKey:@"Phone"];
job.apply = [object objectForKey:@"Apply"];
job.imageFile = [object objectForKey:@"imageFile"];
job.rotation = [object objectForKey:@"Rotation"];
job.location = [object objectForKey:@"Location"];
job.type = [object objectForKey:@"Type"];
job.clearance = [object objectForKey:@"Clearance"];
job.job_description = [object objectForKey:@"Job_Description"];
job.qualifications = [object objectForKey:@"Qualifications"];
destViewController.job = job;
}
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[self clear];
self.canSearch = 1;
[self.searchedBar resignFirstResponder];
[self queryForTable];
[self loadObjects];
}
- (void)configureSearchResult:(SearchedResultCell *)cell atIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
mainTitle = [object objectForKey:@"Position"];
cell.mainTitle.text = mainTitle;
subTitle = [object objectForKey:@"Type"];
cell.detail.text = subTitle;
// Implement this if you want to Show image
cell.showImage.image = [UIImage imageNamed:@"AppIcon.png"];
PFFile *imageFile = [object objectForKey:@"imageFile"];
if (imageFile) {
cell.showImage.file = imageFile;
[cell.showImage loadInBackground];
}
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[searchedBar resignFirstResponder];
if ([self.objects count] == indexPath.row) {
[self loadNextPage];
} else {
PFObject *photo = [self.objects objectAtIndex:indexPath.row];
NSLog(@"%@", photo);
// Do something you want after selected the cell
}
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self.searchedBar resignFirstResponder];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
[self.searchedBar resignFirstResponder];
[self queryForTable];
[self loadObjects];
}
@end
最佳答案
您的代码没有指向现有的作业对象
PFObject *jobs = [PFObject objectWithClassName:@"Jobs"];
要将对象添加到关系中,它应该是其表中的现有对象(如果是新对象,则需要先保存它)
更新:
您的代码应该使用 View Controller 中的属性 job 并将其添加到当前用户关系中,如下所示
- (IBAction)favoriteButtonAction:(id)sender {
PFUser *user = [PFUser currentUser];
PFRelation *relation = [user relationForKey:@"Favorites"];
[relation addObject:job];
[user saveInBackground];
}
如果你用Parse会更好subclasses对于作业对象
#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>
@interface Job : PFObject<PFSubclassing>
@property (nonatomic, strong) NSString *rotation;
@property (nonatomic, strong) NSString *location;
@property (nonatomic, strong) NSString *type;
..
.
.
.
@end
@implementation Tracker
@dynamic rotation, location, type,....;
+ (void)load {
[self registerSubclass];
}
+ (NSString *)parseClassName {
return @"Job";
}
@end
然后修改你的代码如下
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showJobDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Job *job = [self.objects objectAtIndex:indexPath.row];
JobDetailViewController *destViewController = segue.destinationViewController;
destViewController.job = job;
}
}
关于ios - 解析关系 [错误] : can't add a non-pointer to a relation (Code: 111, 版本 : 1. 7.5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31085898/
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="