Reputation: 544
I have the problem in refreshing the table. I create the table like this
for (int i = 0; i < 4; i++)
{
DetailsTable = [[UITableView alloc] initWithFrame:CGRectMake(i*768, 45, 768, 1024) style:UITableViewStyleGrouped];
DetailsTable.dataSource = self;
DetailsTable.delegate = self;
DetailsTable.tag = i + 1;
[scrollView addSubview:DetailsTable];
[DetailsTable release];
}
Whenever I am refreshing the table like this [DetailsTable reloadData]; it refresh the last table only. And other table is not getting refresh
How can refresh all table view in iphone
Upvotes: 2
Views: 129
Reputation: 946
put in for loop where you are going to create
DetailsTable.tag=i
and then for example of edit method of delegate method use this
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (tableView.tag)
{
case 0:
{
//write your code here
break;
}
// like this do all for other remaining tableview
default:
break;
}
}
Upvotes: 0
Reputation: 1
You can not add tables like this. Your next tableView will replace the pre tableView. You should impliment this by init four single tables.
Upvotes: -1
Reputation: 946
this is because in DetailsTable the last table reference is retain so that this occurs Try this add this in .h file
NSMutableArray *tblArr;
add this in .m file
tblArr=[[NSMutableArray alloc] init];
for (int i = 0; i < 4; i++)
{
UITableView *DetailsTable = [[UITableView alloc] initWithFrame:CGRectMake(i*768, 45, 768, 1024) style:UITableViewStyleGrouped];
DetailsTable.dataSource = self;
DetailsTable.delegate = self;
DetailsTable.tag = i + 1;
[scrollView addSubview:DetailsTable];
[tblArr addObject:DetailsTable];
[DetailsTable release];
}
and when you want to relaod all table use this
for (int i = 0; i < 4; i++)
{
[(UITableView *)[tblArr objectAtIndex:i] reloadData];
}
Upvotes: 1
Reputation: 19912
The variable DetailsTable is being replaced with a new one every time in the for loop.
You should create an array of tables instead, like this:
//Declaration
UITableView *DetailsTable[4];
//Implementation
for (int i = 0; i < 4; i++)
{
DetailsTable[i] = [[UITableView alloc] initWithFrame:CGRectMake(i*768, 45, 768, 1024) style:UITableViewStyleGrouped];
...
}
//And to refresh them
for(int i = 0; i < 4; i++)
[DetailsTable[i] reloadData];
Upvotes: 0
Reputation: 4953
you are creating 4 tableView not four cells, and every time you are creating a new instance of the table so when you call the [DetailsTable reloadData]; it refrences the most recent instance of DetailsTable i.e the last table.
Upvotes: 0
Reputation: 39306
You keep overwriting the value of the PersonDetailsTable property in the loop. Therefore the value of that property is the 4th one after the loop exits. You call reloadData against that property which points to the 4th instance of the table you added.
To make that work, you would need an NSMutableArray of table views (instead of the one property reference) and reloading all of them would could be looping with reloadData calls. Of course in your UITableView datasource callbacks, you need to distinguish between which table view is calling you back for data since self is the datasource and delegate for all of them.
Upvotes: 1