我尝试为我的TableView设置一个自定义的附件复选框,并且遇到了这个错误......
读取在NSManagedObject类型的元素上找不到的字典元素的预期方法
我的ViewController代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSManagedObject *device = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
device = [searchResults objectAtIndex:indexPath.row];
}
else
{
device = [self.cart objectAtIndex:indexPath.row];
}
if (cell.accessoryView == nil)
{
// Only configure the Checkbox control once.
cell.accessoryView = [[Checkbox alloc] initWithFrame:CGRectMake(0, 0, 25, 43)];
cell.accessoryView.opaque = NO;
cell.backgroundColor = [UIColor clearColor];
[(Checkbox*)cell.accessoryView addTarget:self action:@selector(checkBoxTapped:forEvent:) forControlEvents:UIControlEventValueChanged];
[cell.textLabel setText:[NSString stringWithFormat:@"%@", [device valueForKey:@"cartProductName"]]];
[(Checkbox*)cell.accessoryView setChecked: [device[@"checked"] boolValue] ];//<-- Errorline
// Accessibility
[self updatetAccessibilityForCell:cell];
return cell;
}
错误发生在setChecked:
行。
我的CoreData是:
Cart.h:
@interface Cart : NSManagedObject
@property (nonatomic, retain) NSString * cartProductName;
@end
Cart.m:
@implementation Cart
@dynamic cartProductName;
@end
我需要一个新房产才能完成吗?
我的ViewController主管:
#import "CartViewController.h"
#import "Checkbox.h"
#import "Cart.h"
@interface CartViewController ()
@property (strong) NSMutableArray *cart;
@end
@implementation CartViewController {
NSArray *cartProducts;
NSArray *searchResults;}
@synthesize searchbar;
对不起,我在编程领域很新......
答案 0 :(得分:0)
将[device[@"checked"] boolValue]
更改为[device.checked boolValue]
您没有访问NSDictionary
而是NSManagedObject
。