我在我的xcode項目中實現了一個SQLite數據庫。我想從數據庫中查看所有的名字進入的tableview,但得到一個錯誤[__NSArrayM objectAtIndex:]:index 9223372036854775807 beyond bounds [0 .. 13]'
NSRangeException」,原因: '*** - [__ NSArrayM objectAtIndex:]:指數 9223372036854775807超出範圍[0 .. 13]'
@interface DisplayViewController()
@property (nonatomic, strong) DBManager *dbManager;
@property (nonatomic, strong) NSArray *arrPeopleInfo;
@end
@implementation DisplayViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.mytableview.delegate = self;
self.mytableview.dataSource = self;
NSString *docsDir;
NSArray *dirPaths;
//Get the directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
self.dbManager = [[DBManager alloc] initWithDatabaseFilename:@"IApp.db"]; //Build the path to keep the database
// _databasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent:@"IApp.db"]];
// [self getcount];
[self loadData];
// [self getcount];
// Do any additional setup after loading the view.
}
- (void)loadData {
// Form the query.
NSString *query = @"select * from iApp";
if (self.arrPeopleInfo != nil) {
self.arrPeopleInfo = nil;
}
self.arrPeopleInfo = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
[self.mytableview reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arrPeopleInfo.count;
// return [arri count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"idCellRecord" forIndexPath:indexPath];
NSInteger indexOfname = [self.dbManager.arrColumnNames indexOfObject:@"firstname"];
NSInteger indexOffname = [self.dbManager.arrColumnNames indexOfObject:@"lastname"];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", [[self.arrPeopleInfo objectAtIndex:indexPath.row] objectAtIndex:indexOfname], [[self.arrPeopleInfo objectAtIndex:indexPath.row] objectAtIndex:indexOffname]];
return cell;
}
如何檢查nsfound?你能告訴我代碼嗎? –