【发布时间】:2014-03-15 19:38:57
【问题描述】:
我尝试为我的 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: 行。
我的核心数据是:
购物车.h:
@interface Cart : NSManagedObject
@property (nonatomic, retain) NSString * cartProductName;
@end
购物车.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;
抱歉,我是编程界的新手……
【问题讨论】:
标签: ios uitableview nsmanagedobject