您好我正在使用HERE中的本教程来创建SQLite数据库并在Table View上查看它。现在我在我的应用程序上面临一个错误,我不知道调试它。如果有人可以帮我解决这个错误,请做!
非常感谢!!!
以下是我当前ViewController.m的代码 我尝试过运行僵尸模式,但它对调试我目前面临的错误没有帮助...
import "ViewController.h"
import "DBManager.h"
@interface ViewController ()
@property (nonatomic, strong) DBManager *dbManager;
@property (nonatomic, strong) NSArray *arrPeopleInfo;
-(void)loadData;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Make self the delegate and datasource of the table view.
self.tblPeople.delegate = self;
self.tblPeople.dataSource = self;
}
-(void)editingInfoWasFinished{
// Reload the data.
[self loadData];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
EditInfoViewController *editInfoViewController = [segue destinationViewController];
editInfoViewController.delegate = self;
}
-(void)loadData{
// Form the query.
NSString *query = @"select * from peopleInfo";
// Get the results.
if (self.arrPeopleInfo != nil) {
self.arrPeopleInfo = nil;
}
self.arrPeopleInfo = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
// Reload the table view.
[self.tblPeople reloadData];
// Load the data.
[self loadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arrPeopleInfo.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60.0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// Dequeue the cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"idCellRecord" forIndexPath:indexPath];
NSInteger indexOfFirstname = [self.dbManager.arrColumnNames indexOfObject:@"firstname"];
NSInteger indexOfLastname = [self.dbManager.arrColumnNames indexOfObject:@"lastname"];
NSInteger indexOfAge = [self.dbManager.arrColumnNames indexOfObject:@"age"];
// Set the loaded data to the appropriate cell labels.
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", [[self.arrPeopleInfo objectAtIndex:indexPath.row] objectAtIndex:indexOfFirstname], [[self.arrPeopleInfo objectAtIndex:indexPath.row] objectAtIndex:indexOfLastname]];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Age: %@", [[self.arrPeopleInfo objectAtIndex:indexPath.row] objectAtIndex:indexOfAge]];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)addNewRecord:(id)sender {
[self performSegueWithIdentifier:@"idSegueEditInfo" sender:self];
}
@end
答案 0 :(得分:1)
问题是你以递归方式调用相同的方法
-(void)loadData{
// Reload the table view.
[self.tblPeople reloadData];
// Load the data.
[self loadData]; // should comment this
}