myClass copyWithZone无法识别的选择器发送到实例

时间:2014-08-15 12:29:00

标签: ios objective-c

当尝试从可变数组中获取对象以及在tableview中该行的值时,我得到错误:

  

* 由于未捕获的异常终止应用' NSInvalidArgumentException',原因:' - [KCNote copyWithZone:]:   无法识别的选择器发送到实例0x15589f60'

下面是我的代码,我看了一下这个错误,大多数地方都讨论了将数据结构从对象复制到新对象的问题,但是对象内容只是整数和字符串,如下所示。

KCNote.h

#import <Foundation/Foundation.h>

@interface KCNote : NSObject
@property (nonatomic) NSInteger NoteID;
@property (nonatomic, strong) NSString *Note;
@property (nonatomic, strong) NSString *Author;
@property (nonatomic, strong) NSString *Date;

@end

我的视图控制器中的代码。

NSMutableArray *Notes;
- (void)viewDidLoad
{
    Notes = [[NSMutableArray alloc] init];
    ...
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"notecell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        }
        // Configure the cell...
        KCNote *note = [Notes objectAtIndex:indexPath.row];

        UILabel *Author =(UILabel *) [cell viewWithTag:1];
        UILabel *Date = (UILabel *) [cell viewWithTag:2];
        UILabel *Note = (UILabel *) [cell viewWithTag:3];

        Author.text = note.Author;
        Date.text = note.Date;
        Note.text = note.Note;


        return cell;
}

使用以下命令将注释添加到数组中:

-(void)getNotes:(NSInteger)courseid{
    [Notes removeAllObjects];
    FMResultSet *s;
    s = [db executeQuery:@"SELECT * FROM notes WHERE CourseID =?;", [NSString stringWithFormat:@"%d", courseid]];
    //s = [db executeQuery:@"SELECT * FROM notes;"];
    if ([db hadError]) {
        NSLog(@"DB Error %d: %@", [db lastErrorCode], [db lastErrorMessage]);
    }
    while ([s next]) {
        NSInteger NoteID = [s intForColumnIndex:0];
        NSString *Note = [s stringForColumnIndex:2];
        NSString *Author = [s stringForColumnIndex:3];
        NSString *date = [s stringForColumnIndex:4];
        KCNote *note = [KCNote new];
        note.NoteID = NoteID;
        note.Note = note;
        note.Author = Author;
        note.Date = date;
        [Notes addObject:note];
    }
    [self.tbl_notes reloadData];
}

0 个答案:

没有答案