I want to insert data from database to table.
I am able to get data from database and insert that into table,but only the last data is inserted in all rows of table. I have used the code as
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
Action *actionInformation;
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 460) reuseIdentifier:@"MyIdentifier"] autorelease];
PrepopulatedActionsDao * preAction = [[PrepopulatedActionsDao alloc] init];
[preAction getDataFromDatabase];
NSMutableArray *allPreActions=[preAction getDataFromDatabase];
for(int i=0;i<[allPreActions count];i++){
actionInformation=[allPreActions objectAtIndex:i];
cell.textLabel.text = [NSString stringWithFormat: @"%@",actionInformation.action];
}
}
return cell;
}
Here PrepopulatedActionsDao is the class where I am getting all datas from database.
I want to insert all datas of database in table not only the last one.
please anybody help.
There is no need of the for loop. The
cellforrowmethod is called for every row in the tableview. So u just need to put the following linecell.textLabel.text = [NSString stringWithFormat: @"%@",[[allPreActions objectAtIndex:indexPath.row] action];instead of the for loop.Hope this solves your problem.