重新加载数据问题
我正在尝试从我的 tableView 重新加载数据。当从它自己的空虚中调用它时,它不起作用并且什么也没有发生。然而,当我环顾四周时,当我删除一个单元格时它就起作用了。我认为这与我的 INIT 有关。你能帮我解决吗?谢谢。
下面是我的代码!
- (id) init {
//NSLog(@"%@", theUserID);
// Set up database connection
NSString *myDBTwo = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"flashpics.db"];
databaseTwo = [[Sqlite alloc] init];
[databaseTwo open:myDBTwo];
//Initialize the array.
listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObject:@"hi!"];
// Add to array to display in the tableView
NSArray *listOfItemsTwo = [databaseTwo executeQuery:@"SELECT * FROM albums"];
for (NSDictionary *rowone in listOfItemsTwo) {
NSString *getName = [rowone valueForKey:@"name"];
if (getName != NULL) {
[listOfItems addObject:getName];
[getName release];
}
}
//[database release];
return self;
}
这是我的空白:
- (void)refreshTableView {
[(UITableView *)self.view reloadData];
//[self.tableView reloadData];
}
提前致谢。
I am attempting to reload the data from my tableView. When calling it from it's own void, it doesn't work and nothing happens. However, when looking around it works when I delete a cell. I am thinking it has something to do with my INIT. Can you help me solve it? Thanks.
Below is my code!
- (id) init {
//NSLog(@"%@", theUserID);
// Set up database connection
NSString *myDBTwo = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"flashpics.db"];
databaseTwo = [[Sqlite alloc] init];
[databaseTwo open:myDBTwo];
//Initialize the array.
listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObject:@"hi!"];
// Add to array to display in the tableView
NSArray *listOfItemsTwo = [databaseTwo executeQuery:@"SELECT * FROM albums"];
for (NSDictionary *rowone in listOfItemsTwo) {
NSString *getName = [rowone valueForKey:@"name"];
if (getName != NULL) {
[listOfItems addObject:getName];
[getName release];
}
}
//[database release];
return self;
}
Here's my void:
- (void)refreshTableView {
[(UITableView *)self.view reloadData];
//[self.tableView reloadData];
}
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您过度释放了
getName
,所以我预计它会崩溃。但是,如果调用-refreshTableView
时没有发生任何事情,那么我会期望self.view
为nil
。您应该验证以下内容:refreshTableView
实际上被调用self.view
在使用时不是nil
tableView:cellForRowAtIndexPath :
被调用,并在请求时返回正确配置的单元格You are over-releasing
getName
, so I would expect this to crash. But if nothing is happening when-refreshTableView
is called, then I would expect thatself.view
isnil
. You should verify the following:refreshTableView
is actually calledself.view
is notnil
at the point that it is usedtableView:cellForRowAtIndexPath:
is called, and returns a properly configured cell when requested