iphone segmented control and uitableview - iphone

I have a UITableView with a segmented control at the top. When you tap on the different segments, I want the table to reload with a new different sized array. I have tried everything including [self.tableView reloadData]. When you click on a different tab now, it only changes the cells that are out of view and does not add any more. Any ideas??? Thanks.

In your numberOfRowsinSection method, are you returning the count of the correct datasource when the segment selection is switched? When you select a segment, you would need to call 'reloadData' on the tableview, you would need to check the count you are returning from 'numberOfRowsInSection' and you would need to use the correct datasource in cellForRowAtIndexPath to provide your cell contents.

Related

looping through uitableview sections to change section header frame

I have a grouped UITableView with many sections, however, I want to iterate through these sections after i tap a UIButton, so viewForHeaderInSection is useless in this case, I want to iterate through sections to change their headers frames, Im struggling to do it but to no avail until now.
I'd be grateful to anyone who helps me with this.
viewForHeaderInSection gets called every time you call ReloadData on a table view.
So you could have a Boolean that gets set to yes every time your button is pressed, and also call reloadData in the button's action. In viewForHeaderInSection, check the value of the bool, if it's true, set the size to what you want when the button is pressed, if false set it to the normal size.
I hope this helps.
After you header view's datasource iterated and changed in whichever you wish way, call
[mytable reloadData]
And your header views are redrawn. Simple and clearly you have not tried that before asking, next time do it.

iphone sdk stay the selection colour of cell in UItableview?

How to get the selection cell still in the selected state in uitableview. Actually I am pushing a view from a tableview when came back then the selection cell is deseleted. I want to be show the previous selection cell when came back also how to do that.
In didselectrowatindexpath use the method selectRowAtIndexPath:animated:scrollPosition: and the row stays selected.
when you are going and coming back from anotherview make sure that save the selectedCell and then in viewwillappear method reloaddata.In cellforindexpath write the code of selection style uitableviewcellselectionstyleblue.
first, you can store the selected indexPath in user default in the didSelectRowAtIndexPath method.(maybe you can store a indexPath that is bigger than your table view's row count to indicate initialization stage, which means that no row has ever been selected)
then, you can load the stored indexPath in the viewDidLoad method using
tableView selectRowAtIndexPath:<#(NSIndexPath *)#> animated:<#(BOOL)#> scrollPosition:<#(UITableViewScrollPosition)#>
meanwhile, you can do some check (like mentioned above or something else) to check if there's nothing selected yet.(saving a bool in user defaults works, too)

Help Using UITableView for High Score Page

I am making a simple gaming app, implementing a tab bar controller. The second tab, or high score page is what I am having problems with. I am able to populate the UITableView with an initial array of objects, however I can't seem to add new cells. Now I read about User entered cells, but how exactly would I extract the winner from one tab to populate the UITableView in the high score tab? Thank you for your time!
For adding new cells to your UITableView, the most straightforward way would be by simply reloading the entire table view [UITableView reloadData].
Assuming that you are storing the cell-contents in a mutable array, simply add those new entries to that array and reload the table.
You can update your array and call reloadData on table view to reload it and also if you want to add cell at a specific position you can use
(void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:

iPHONE SDK - tableview, remembering how much it is scrolled?

i was wondering how do i do this?
I wish to make a tableview configured in a way that if i scroll down a tableview and click on one row, i will be brought to another view. But when i click a back button of some sort. i return to the tableview but still viewing that particular row. kinda like the iPod table in the iPhone? Remembering scrolled position?
i just want to know how to do the 'remembering scrolled position' part.
Save your index path in tableView:didSelectCellAtIndexPath: before pushing the new view, use it later. This will give you the NSIndexPath pointing at the cell that was selected by the user, not necessarily give you the same position it was at before they tapped the item. So keep that in mind.
Continue from jer's answer. You can use indexPath when calling this method in tableView:
UITableView selectRowAtIndexPath:animated:scrollPosition:

IPhone - Get reference to cells that are currently on screen

I have a Table View Controller with cells. I want to update the text that is displayed on the visible UITableViewCells. Is there a way to get a reference to the cells that are currently on the screen?
You can query the visible cells;
[myTableOutlet visibleCells];
Where myTableOutlet refers to your UITableView, and visibleCells returns an array of table cells. You could also use indexPathsForVisibleRows, which will return an array of index paths for the rows that are currently visible.
If you put the code in a ,notification triggered, function, you could update only the currently visible cells.
What you can do is go and ask for the cells at index paths using - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath, if they are not nil, you know they are on the screen and you can do what you wish with them. Also if you know the visible rectangle on the screen (which shouldnt be hard to get) you can use tableViews - (NSArray *)indexPathsForRowsInRect:(CGRect)rect and you can get all your visible index paths and use cellForRow in order to get the cells back.
As long as this is marked as answer, I stand corrected, like others said you can do [tableView visibleCells]
Call the reloadData method of the UITableView. It will force the table view to update all the visible cells information (check the documentation for more information).