gpt4 book ai didi

ios - -[NSDictionary initWithObjects :forKeys:]: count of objects (0) differs from count of keys (2)

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:21 25 4
gpt4 key购买 nike

我得到的错误是

-[NSDictionary initWithObjects:forKeys:]: 对象数 (0) 不同于键数 (2)'

这是我保存 plist 的代码。

    @interface setting : UIViewController{
UIDatePicker *datePicker;
IBOutlet UILabel * morningtime;
UIDatePicker *afternoonpicker;
NSString*morningtime1;
NSString*afternoontime1;
IBOutlet UILabel *afternoontime;
}
@property (nonatomic,retain) IBOutlet UIDatePicker *datePicker;
@property (strong, nonatomic) IBOutlet UIDatePicker *afternoonpicker;

@property (nonatomic, retain) IBOutlet NSString *morningtime1;

@property (nonatomic, retain) IBOutlet NSString *afternoontime1;
@property (nonatomic, retain) IBOutlet UILabel *morningtime;

@property (nonatomic, retain) IBOutlet UILabel *afternoontime;
@property (weak, nonatomic) IBOutlet UIButton *morning;




- (IBAction)savetext:(id)sender {
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];

self.morningtime1 = morningtime.text;
self.afternoontime1 = afternoontime.text;
NSDictionary *plistDict = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: morningtime1, afternoontime1, nil] forKeys:[NSArray arrayWithObjects: @"Morning", @"Afternoon", nil]];

NSString *error = nil;
// create NSData from dictionary
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

// check is plistData exists
if(plistData)
{
// write plistData to our Data.plist file
[plistData writeToFile:plistPath atomically:YES];
}
else
{
NSLog(@"Error in saveData: %@", error);
}
}

最佳答案

morningtime1 几乎肯定是 nil,提前结束数组列表。

如果你在这里使用了新的数组文字语法:

@[morningtime1, afternoontime1];

您会遇到崩溃,因为将 nil 分配给 NSArray 元素是非法的。

关于ios - -[NSDictionary initWithObjects :forKeys:]: count of objects (0) differs from count of keys (2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15909714/

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