0

現在、オブジェクトからデータを読み取ろうとしているテーブルビューセルに関してエラーが発生しています。私はデータベースにアクセスし、すべての行をオブジェクトとしてNSMUtable配列に格納しています。これは正常に機能しているようです。しかし、テーブルビューにその配列を読み取らせたい場合は、「null」を取得し続けます。どんな助けでも大歓迎です。

エラー

-[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:文字列型ではないオブジェクトを呼び出しているようです。コードには、エラーが発生した場所が表示されません。isEqualToString:両方のオブジェクトを使用するには、NSStringタイプが必要です。オブジェクトを文字列と比較する場合は、 isEqual:代わりにを使用してください。

于 2013-03-16T15:55:08.403 に答える
0

ここでエラーが発生する可能性があります

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

これらの行をに変更します。

 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 に答える