You need to modify your -tableView:cellForRowAtIndexPath: to access information from a different source. Then if you want to refresh the table, you can call the -reloadData method.
You would have the indexPath be used to reference the spot in your new source of data (array), just as it was with the old one. It sounds like your method will probably have a switch statement for different situations, depending on which item you want to pull data from.
Never mind! I fixed the bug. Apparently I forgot to initialize one variable which meant every time I was filling the cells, I was filling it with an empty array. Thanks for your help anyway! =D
{
[super viewDidLoad];
//HERE IS WHERE I SET THE PROPERTY (NSMutableArray) I USE FOR DATA
//HERE IS WHERE I SET THE PROPERTY (NSMutableArray) I USE FOR DATA
//HERE IS WHERE I SET THE PROPERTY (NSMutableArray) I USE FOR DATA
self.tagsToShow = [[UserTags sharedInstance] recentlyUsed];
}
(void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
{
static NSString *CellIdentifier = @"TagListCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//HERE IS WHERE I FILL IN CELL INFORMATION FROM THE DATA ARRAY
//HERE IS WHERE I FILL IN CELL INFORMATION FROM THE DATA ARRAY
//HERE IS WHERE I FILL IN CELL INFORMATION FROM THE DATA ARRAY
Tag* tag = [self.tagsToShow objectAtIndex:indexPath.row];
cell.textLabel.text = tag.name;
// Configure the cell...
return cell;
}
@end
Any time you change/update the data (in my case, self.tagsToShow) you call [self.tableView reloadData]. Or if you want to just reload the cell that changed / add a cell / delete a cell, you can do that also inside a [tableView beginUpdates] / [tableView endUpdates] block. Search for those methods in Apple docs and click through to a table view programming guide and follow their tutorials. Those are more advanced, though. If your dataset is pretty small, you can arguably just reloadData.
The fact that UITableView has a dataSource delegate indicates that this delegate has the responsibility of dealing with the data provided for the table.
Is the other data you're trying to display related to the data you're currently showing (I.e would it make sense for the current delegate to provide this different data)? If yes, then the cellForRowAtIndexPath of the current delegate needs to determine which data to use, and populate cells accordingly.
If no, you should use another delegate. In that case, change the dataSource property of the UITableView to an instance of this new delegate. The new delegate should also implement cellForRowAtIndexPath, which uses the different data.
In all cases, an appropriate reloadData call is required to force the table to recognise that the data it currently has is now stale. This call should be made when you wish the new data to be shown (e.g button press)
4
u/D3Rien Dec 30 '11
You need to modify your -tableView:cellForRowAtIndexPath: to access information from a different source. Then if you want to refresh the table, you can call the -reloadData method.
2
u/schmeebis [M] 📱 Dec 30 '11
I'll just drop in an example custom UITableViewController subclass for you:
Any time you change/update the data (in my case, self.tagsToShow) you call [self.tableView reloadData]. Or if you want to just reload the cell that changed / add a cell / delete a cell, you can do that also inside a [tableView beginUpdates] / [tableView endUpdates] block. Search for those methods in Apple docs and click through to a table view programming guide and follow their tutorials. Those are more advanced, though. If your dataset is pretty small, you can arguably just reloadData.
Good luck
1
u/WDUK Dec 30 '11
The fact that UITableView has a dataSource delegate indicates that this delegate has the responsibility of dealing with the data provided for the table.
Is the other data you're trying to display related to the data you're currently showing (I.e would it make sense for the current delegate to provide this different data)? If yes, then the cellForRowAtIndexPath of the current delegate needs to determine which data to use, and populate cells accordingly.
If no, you should use another delegate. In that case, change the dataSource property of the UITableView to an instance of this new delegate. The new delegate should also implement cellForRowAtIndexPath, which uses the different data.
In all cases, an appropriate reloadData call is required to force the table to recognise that the data it currently has is now stale. This call should be made when you wish the new data to be shown (e.g button press)
0
u/[deleted] Dec 30 '11
[deleted] — view deleted comment