0

现在,我收到有关尝试从对象读取数据的表视图单元格的错误。我正在访问一个数据库,将所有行作为对象存储到一个 NSMUtable 数组中,这似乎工作正常。但是当我希望表格视图读取该数组时,我不断得到“空”。任何帮助将不胜感激。

错误

-[AttendeeData isEqualToString:]:无法识别的选择器发送到实例 0x751ca80 2013-03-16 11:40:52.499 ExpoRequestLite[39716:c07] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,

@interface DashLandingViewController ()

@end

@implementation DashLandingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self){
            // Custom initialization
        }
        return self;
}

- (void)viewDidLoad {

       [super viewDidLoad];

        entries  = [[NSMutableArray alloc]init];
        _attendeeDataToPush = [[AttendeeData alloc]init];

        [self openDB];

        NSString *sql = [NSString stringWithFormat:@"SELECT * FROM data"];
        sqlite3_stmt *statement;

        if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)== SQLITE_OK) {
            while(sqlite3_step(statement) == SQLITE_ROW){
                NSLog(@"got all attendees");

               NSString *firstName = [[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];

                _attendeeDataToPush.firstNameValue = firstName;

                [entries addObject:_attendeeDataToPush];
                NSLog(@"array has %@", [[entries objectAtIndex:0] firstNameValue]);

           }
      }

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [entries count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
       NSLog(@"selected firstname is %@", [[entries objectAtIndex:0] firstNameValue]);
        cell.textLabel.text = [entries objectAtIndex:indexPath.row];
        return cell;
    }

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
}


@end
4

2 回答 2

1

错误表明您的代码中的其他地方有错误,请发布您的完整代码。从您的错误看来,您正在调用 isEqualToString:不是字符串类型的对象。您的代码未显示您在哪里得到错误。For Using isEqualToString:both objects 应该是NSString类型。如果您将对象与字符串进行比较,请 isEqual:改用。

于 2013-03-16T15:55:08.403 回答
0

Errors may happening here

 NSLog(@"selected firstname is %@", [[entries objectAtIndex:0] firstNameValue]);
 cell.textLabel.text = [entries objectAtIndex:indexPath.row];

Modify these lines to,

 if([entries count] > indexPath.row){

     AttendeeData *attendeeData = [entries objectAtIndex:indexPath.row];
     NSLog(@"selected firstname is %@", attendeeData.firstNameValue);
    cell.textLabel.text = attendeeData.firstNameValue;
}
于 2013-03-16T16:04:01.513 回答