TableView's viewWillAppear() called but data is not refreshed - iphone

Sometimes tiny looking problem is ignored to handle in the last but you never know that will become nightmare for you, happening with me.
Thanks in advance, problem my app's settings page contains tableView and every setting element is one of the view. One of the setting item (row) offers show expands a few list of items in another listTableView. After making a selection in listTableView when i come back to my settings tableView using navigationItem.leftButton (Back), selected item value overlaps the previous item's value, in the sense [tableView reloadData] in viewWillAppear works fine but tableView rows are not fresh drawn. It doesn't refresh the cell's UI.
Note that if settingTableView has any subview like UIButton etc it has the latest value, i can use that as workaround but the only problem is when is select this row again Selection has old value that overlaps new value on selecting the row.
I will appreciate any suggestion or sample code using will be great help.
Thanks a ton
Amit Singh

Use [tableView reloadData]; in your viewWillAppear method.

or use [tableView reloadData]; in viewDidAppear method

The problem you are facing is perhaps due to portion of cell that is reusable and the one that is not reused. Check out the code you are writing inside the block of
if(cell==nil){}
components you have created inside block will not get recreated and others might be recreating causing the overlapping on the cell.

In my case, I had to use [self.tableView reloadData]; rather than [tableView reloadData]; in the viewWillAppear method.

Related

iphone - scrollRectToVisible issue

This functions perfectly, but I want to make it an once-function, not fixed-function. When I change tableview with other data, the data displays at the index from previous tableview. So my solution to this is implementing the code below. When I implement this, it works, but when I scroll down, it scrolls up all the time, so it is virtually impossible to scroll down further. Any idea how to make it performs only once when I change tableview?
The code:
[tableView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
Edit 21 august:
Guys, thank you very much! The code was in cellforrowatindexpath. I moved it to inside the function which changes tableview and it works like a charm :D
You could override the reloadData method if that is how you are reloading the Table View with new data and put the code in there. Something like this in your table view controller should suffice:
- (void)reloadData {
[super reloadData];
[tableView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
}
If it's scrolling up every time you scroll down, I assume you put the code in the cellForRowAtIndexPath method which will get called every time you want to present the cell. This is not the correct place to put that code.
It IS a once-function. Most probably, this code of yours is executing again & again. If you have kept this in a function such as cellForRowAtIndexPath:, which is called frequently, that may be the cause of this problem. Where have you put it?
HTH,
Akshay

can I reload UITableViewController with out reapearing or reloading the table

I am developing an app in which I have to delete the contacts from table ,problem is that when i delete one contact ,I have switch from one view to another then I can see the changing b/c i put the reload method in viewAppear any suggestion?
In general you should avoid to use reloadData to refresh the content of a UITableView, you should only do it if you can't avoid it (ie you replace everything in your table) or the user won't see it (ie in viewWillAppear).
I would suggest to use insertRowsAtIndexPaths:withRowAnimation: to insert single rows and deleteRowsAtIndexPaths:withRowAnimation: to remove rows.
So you get the indexPath of the row when you delete a contact and call [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deletedIndexPath] withRowAnimation:UITableViewRowAnimationFade]
Those details make the difference between a app and a good app.
you can call [self.tableView reloadData]; to reload the table view by staying on the current view.
You can immediately reload table after deleting the contact !
Just call [self.tableView reloadData] in the UITableViewController after the data has been modified. This will update the table view to and reflect the new state of the data.

update content of custom UITableViewCell not working

I am creating a custom UITableViewCell as in
http://www.e-string.com/content/custom-uitableviewcells-interface-builder
all is working fine with no problem. The loading of data is correct, which proved that the linking in IB is correct too.
I am trying to update the content, a UILabel, on the custom cell from another function in the class which take a reference to the table containing the cell and the indexPath. However the label is not being reset the value desired.
My problem is similar to this: Cannot update Custom UITableViewCell but it does not have a solution :(
I tried calling [myTable reloadData] and [cell reloadInputViews] but neither worked for me.
Not sure how to do this can any one suggest something?
Cheers
AF
UPDATE:
I found what was going wrong!
In my current code i am receiving the updates that i need to show in the UILabel from another thread, which calls the updating function on the client object directly (i pass reference to it to the second thread), and that is wrong!!
I have used instead [myClientObject performSelectorOnMainThread:myUpdatingFunction waitUntilDone:NO] and it all worded as charm...
Thanks for the help and sorry for not posting the code...
try:
[cell setNeedsDisplay];
or:
[cell.custumLabel setNeedsDisplay];
that forcing the cell/label to draw himself again
good luck

How to auto-scroll UITableView?

I am trying to do something interesting.
I am pulling some JSON data and populating cells in a UITableView. How can I make the UITableView scroll ever second or so? I want to give the effect that as new data is coming in, the table is scrolling, so it is streaming.
Any ideas?
Yes, use scrollToRowAtIndexPath:atScrollPosition:animated:.
You could also use UIScrollView's scrollRectToVisible:animated: if you want to have more finegrained control and can calculate exactly what your scroll position should be in pixels. (UITableView is subclass of UIScrollView.)
But if you are just adding cells, sounds like you could also just use insertRowsAtIndexPaths:withRowAnimation:, this is also "interesting."
Just do this
[table reloadData];
NSIndexPath *myIP = [NSIndexPath indexPathForRow:[arrayIn count]-1 inSection:0] ;
[table scrollToRowAtIndexPath:myIP atScrollPosition:NULL animated:YES];
in anywhere where arrayIn is your array by which your table populate.
you can use uitableviews scrollToRowAtIndexPath to do this....heres a link reference
You can call this method whenever as youd like to scroll your tableview
And you can call performSelector:withObject:afterDelay: for the timer effect - although if you are really pulling in data every second, it's best to just reloadData as you go.

UISegmentControl and UITableViewController animation

How can I animate my "removal of tableviewitems" when the user changes between segments in the UISegmentControl?
The behaviour should be similar to "Missed/All" calls in the Phone App.
The deleteRowsAtIndexPaths:withRowAnimation: and insertRowsAtIndexPaths:withRowAnimation: will provide the animation for you.
If you need to perform a more complex operation (inserts and deletes), you start a block. similar to a UIView animation block:
[tableView beginUpdates];
//add and delete
[tableView endUpdates];
Bear in mind you will need to update the model to reflect the changes in the table.
UITableView can be sent a message: deleteRowsAtIndexPaths:withRowAnimation:
The withRowAnimation argument determines the type of animatio that will be used in removing the cell.
I don't know if any of those animations match the missed/all functionality exactly though. If they don't, I'm guessing you will have to set up an animation to collapse the height of the cells before removing them.