gpt4 book ai didi

ios - 尝试将核心数据对象获取到TableView时出现“NSInvalidArgumentException”

转载 作者:行者123 更新时间:2023-12-01 21:58:57 25 4
gpt4 key购买 nike

尝试将核心数据对象获取到tableview并获得Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "seminar"; desired type = NSString; given type = UITextField;的异常
TeacherViewController.m保存数据,获取并在TeacherDataViewController.m的tableview中显示
**

TeacherViewController.h

**

- (IBAction)btnsubmit:(UIButton *)sender {
NSManagedObjectContext *context = [self managedobjectcontext];
NSManagedObject *new = [NSEntityDescription insertNewObjectForEntityForName:@"Teacher" inManagedObjectContext:context];
[new setValue:self.txtseminar forKey:@"seminar"];
[new setValue:self.txtassignment forKey:@"assignment"];
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"can't save!! %@ %@", error, [error localizedDescription]);
}
}

**

TeacherDataViewController.m

**
- (void)viewDidLoad {
[super viewDidLoad];
myarray = [[NSMutableArray alloc]initWithObjects:([self.lblsemnr.text valueForKey:@"seminar"]), ([self.lblassmnt.text valueForKey:@"assignment"]), nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.devices.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = [myarray objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [myarray objectAtIndex:indexPath.row];
return cell;
}

不保存任何数据并引发上述异常

最佳答案

看起来在下面的行中,您正在将txtSeminar设置为研讨会。 txtSeminar似乎是一个TextField,您应该使用txtSeminar.text

[new setValue:self.txtseminar forKey:@"seminar"];

关于ios - 尝试将核心数据对象获取到TableView时出现“NSInvalidArgumentException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60717773/

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