In my app.i have some classes and inside one class I am calling method in other class. In my other class I have a table view and an array “data”. When the query is executed in this method then I am adding the data obtained from the execution of the query to the array and then I am calling reload data for the table view. But to my surprise table view is not getting reloaded and I am not getting any sort of data on the table view. It is showing just a blank table view.
The method which is called from other class:
-(void)searchImagesInCategory:(NSString *)string
{
data=[[NSMutableArray alloc]init];
string1=string;
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory= [paths objectAtIndex:0];
NSString *path=[documentsDirectory stringByAppendingPathComponent:@"Table.sqlite"];
//Open the database
//might have to make database as property
if(sqlite3_open([path UTF8String], &dataBase) ==SQLITE_OK)
{
sqlite3_stmt *statement;
NSString *strSQL = [[NSString alloc]init];
strSQL = @"select ImageName from tblLanguageElement where Category='";
strSQL = [[strSQL stringByAppendingString:string1] stringByAppendingString:@"'"];
const char *bar = [strSQL UTF8String];
//strSQL = [strSQL stringByAppendingString:"''"];
//NSLog(strSQL);
if(sqlite3_prepare(dataBase, bar, -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
NSLog(@"%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]);
[data addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
}
tableView1.delegate=self;
tableView1.dataSource=self;
}
}
[tableView1 reloadData];
}
My cell for row at index path method:-
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.imageView.image= [UIImage imageNamed:[data objectAtIndex:indexPath.row]];
return cell;
}
Why i am not getting the reloaded Table view.Please help.
Thanks,
Christy
In your method you are re-initializing your “data” array. Try making this a local variable by declaring it in your header file and then in your viewDidLoad method call:
Also there is no need to reset the delegate and data source. Just do it once and leave it.
This is an edit from something else I have seen. You need to bind your variable and not just append the string. Here is an example….
So this is the SQL statement that will get the stuff from the database. To call this method you go something like this.
I hope this helps any questions just ask.