gpt4 book ai didi

ios - 'NSInvalidArgumentException',原因 : '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]'

转载 作者:行者123 更新时间:2023-12-01 17:19:11 27 4
gpt4 key购买 nike

我的 Storyboard中有两个 UITextField,用于接收用户输入的数字,minPrice 和 maxPrice。当我在模拟器中点击提交时,应用程序崩溃并且我收到以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]'
*** First throw call stack:
(
0 CoreFoundation 0x02a881e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x026468e5 objc_exception_throw + 44
2 CoreFoundation 0x02a4e376 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 390
3 CoreFoundation 0x02a7bc29 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 73
4 Parse+Storyboard 0x0000b5b5 -[CriteriaViewController submitButton:] + 757
5 libobjc.A.dylib 0x02658880 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x013083b9 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x01308345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x01409bd1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x01409fc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x01409243 -[UIControl touchesEnded:withEvent:] + 641
11 UIKit 0x01347ddd -[UIWindow _sendTouchesForEvent:] + 852
12 UIKit 0x013489d1 -[UIWindow sendEvent:] + 1117
13 UIKit 0x0131a5f2 -[UIApplication sendEvent:] + 242
14 UIKit 0x01304353 _UIApplicationHandleEventQueue + 11455
15 CoreFoundation 0x02a1177f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x02a1110b __CFRunLoopDoSources0 + 235
17 CoreFoundation 0x02a2e1ae __CFRunLoopRun + 910
18 CoreFoundation 0x02a2d9d3 CFRunLoopRunSpecific + 467
19 CoreFoundation 0x02a2d7eb CFRunLoopRunInMode + 123
20 GraphicsServices 0x02ce55ee GSEventRunModal + 192
21 GraphicsServices 0x02ce542b GSEventRun + 104
22 UIKit 0x01306f9b UIApplicationMain + 1225
23 Parse+Storyboard 0x000020ed main + 141
24 libdyld.dylib 0x038e2701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

CriteriaViewController.h:

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "SearchViewController.h"

@interface CriteriaViewController : UIViewController{

IBOutlet UISegmentedControl *Segment;
}


//@property (nonatomic) IBOutlet UITextField *itemSearch;
@property (weak, nonatomic) IBOutlet UITextField *minPrice;
@property (weak, nonatomic) IBOutlet UITextField *maxPrice;
@property (nonatomic, copy) NSNumber *chosenCategory;
@property (weak, nonatomic) NSString *itemCondition;
@property (weak, nonatomic) NSString *itemLocation;
@property (weak, nonatomic) NSString *itemSearch;

@end

CriteriaViewController.m:

    #import "CriteriaViewController.h"

@interface CriteriaViewController ()
@property (weak, nonatomic) IBOutlet UISegmentedControl *itemConditionSegment;
@property (weak, nonatomic) IBOutlet UISegmentedControl *itemLocationSegment;


@end

@implementation CriteriaViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{

[super viewDidLoad];

// Condition UISegment
UISegmentedControl *conditionSegmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Only New", @"Any", nil]];
conditionSegmentedControl.frame = CGRectMake(87, 190, 157, 30);
conditionSegmentedControl.selectedSegmentIndex = 0;
conditionSegmentedControl.tintColor = [UIColor blackColor];
[conditionSegmentedControl addTarget:self action:@selector(ConditionSegmentControlAction:) forControlEvents: UIControlEventValueChanged];
[self.view addSubview:conditionSegmentedControl];


// Location UISegment
UISegmentedControl *locationSegmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Fast Shipping", @"Large Selection", nil]];
locationSegmentedControl.frame = CGRectMake(67, 275, 200, 30);
locationSegmentedControl.selectedSegmentIndex = 0;
locationSegmentedControl.tintColor = [UIColor blackColor];
[locationSegmentedControl addTarget:self action:@selector(LocationSegmentControlAction:) forControlEvents: UIControlEventValueChanged];
[self.view addSubview:locationSegmentedControl];

// Submit button
UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // Create Round Rect Type button.
submitButton.frame = CGRectMake(100, 100, 100, 100); // define position and width and height for the button.
[submitButton setTitle:@"Submit" forState:UIControlStateNormal];

[submitButton addTarget:self action:@selector(submitButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:submitButton];

}

- (void)ConditionSegmentControlAction:(UISegmentedControl *)segment
{
if(segment.selectedSegmentIndex == 0)
{
// set condition to new
self.itemCondition = @"new";
}
else if (segment.selectedSegmentIndex == 1)
{
// set condition to all
self.itemCondition = @"all";
}
}

- (void)LocationSegmentControlAction:(UISegmentedControl *)segment
{
if(segment.selectedSegmentIndex == 0)
{
// set location to us
self.itemLocation = @"US";
}
else if (segment.selectedSegmentIndex == 1)
{
// set clocation to worldwide
self.itemLocation = @"Worldwide";
}
}


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


//add all the info to users respective new category object
- (IBAction)submitButton:(id)sender
{
if (self.minPrice.text.length > 0 && self.maxPrice.text.length > 0) {

[PFCloud callFunctionInBackground:@"userCategorySave"
withParameters:@{@"categoryId": self.chosenCategory,
@"minPrice": self.minPrice,
@"maxPrice": self.maxPrice,
@"itemCondition": self.itemCondition,
@"itemLocation": self.itemLocation
}
block:^(NSString *result, NSError *error) {

if (!error) {
NSLog(@"Criteria successfully saved.");

[self performSegueWithIdentifier:@"SearchCategoryChooserToMatchCenterSegue" sender:self];

}
}];

}

}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {



[PFCloud callFunctionInBackground:@"addToMatchCenter"
withParameters:@{
// @"searchTerm": self.itemSearch,
@"categoryId": self.chosenCategory,
// @"minPrice": self.minPrice,
// @"maxPrice": self.maxPrice,
// @"itemCondition": self.itemCondition,
// @"itemLocation": self.itemLocation,
}
block:^(NSString *result, NSError *error) {

if (!error) {
NSLog(@"'%@'", result);
}
}];

// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.

}



@end

云代码:

Parse.Cloud.define("userCategorySave", function(request, response) {


var userCategory = Parse.Object.extend("userCategory");
var newUserCategory = new userCategory();
newUserCategory.set("categoryId", request.params.categoryId);
newUserCategory.set("minPrice", request.params.minPrice);
newUserCategory.set("maxPrice", request.params.maxPrice);
newUserCategory.set("itemCondition", request.params.itemCondition);
newUserCategory.set("itemLocation", request.params.itemLocation);
newUserCategory.set("parent", Parse.User.current());

newUserCategory.save({

success: function (){
console.log ('userCategory successfully created!');
response.success('userCategory successfully created!');
},

error: function (){
console.log('error!!!');
response.error('Request failed');
}

});
});

我认为问题是 UITextFields 以我的云代码不喜欢的格式发送数字。除了这个错误之外,我想设置它以便在此字段中输入值时只允许使用数字。

我如何以编程方式创建这两个字段,以便以与云代码兼容的格式发送数据,并且只允许数字?

最佳答案

你的一个属性——它看起来像 itemCondition——显然是 nil。这可能是因为你的属性很弱,所以在你有机会查看它之前变量被取消了,或者可能是因为你选择的段不是你正在测试的值之一,因此变量永远不会设置。我不明白为什么这些字符串属性很弱,我强烈怀疑它们不应该如此。

关于ios - 'NSInvalidArgumentException',原因 : '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23897751/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com