update content of custom UITableViewCell not working - iphone

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

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

cellForRowAtIndexPath returns nil on device

I spent few hours trying to resolve one very strange issue, but I really don't know how to proceed.
I have a grouped UITableView referenced from XIB populated with custom (subclassed) UITableViewCell cells. All the cells (two section with one cell each) are visible and I am trying to get one of them by calling:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
LocationSearchFilterCell *cell = (LocationSearchFilterCell *)[filterTable cellForRowAtIndexPath:indexPath];
On Simulator 4.2 the cell is returned properly;
On Device 4.0.x the code returns NIL;
On Simulator 4.0.x the code returns NIL;
On Simulator 4.1 the cell is returned properly BUT NOT on Device 4.1.
The strangest thing is that I am using this approach on few other places within the application and the cell is always returned properly. I guess it is some strange combination of me doing something differently combined with some iOS bug.
Any idea ?
P.S. In situation where NIL is returned, by using GDB I get the pointer of the cell when it is created and call:
(gdb) po (void *)[filterTable indexPathForCell:(UITableViewCell *)0x7b08520]
and I get a valid index path (that matches the one I am providing) which means the cell is valid and present into the table view.
I have even tried passing the object returned by this last call (by pointer) and I still get NIL.
Interesting,
It turned out someone is hiding the table view before I try to get the cell (stupid me :)).
What I was doing was, triggering an animation to hide the table view (nested into some methods I am calling from the method where I try to get the cell). Because I was stopped on a breakpoint the animation was also stopped, so it seamed to me like the table view is visible.
What I don't understand still is why the table view is threaded as hidden although the animation is still not finished (and I only change the frame in the animation and set the table hidden after the animation is finished) ?
I guess the answer to this question is the key point why on different combinations of Device / Simulator / iOS I get different behavior. Anyway the solution is as simple as moving the two lines I've posted above at the top of the method.
Thanks to Rits for his question that triggered my reasoning ;)
regards

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

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.

UIActivityIndicatorView Trouble

This is a bit of a silly question but I don't know how to get around it.
I am making an iphone app and I am just trying to display a progress wheel while my UITableView is loading. I try to test if the view is loading but I get an error:
'request for member 'loading' is something not a structure or a union'. So, I'm not sure how I am supposed to test for when I should show the wheel. maybe I have mistyped something? I don't know, but I am getting pretty frustrated with this silly problem. So, any help would be appreciated. Thanks!
- (void) updateWheel {
//curtable is a uitableView
//wheel is a uiactivityIndicatorView
if (!curTbl.loading) { //THE ERROR IS FOR THIS LINE
[wheel stopAnimating];
} else {
[wheel startAnimating];
}
}
There is no loading property of a UITableView, which would be why you are getting a compile error on that line of code. As DarkDust said, you use a data source protocol to feed data into the cells of a table view. As views come into view, the system requests the cell and data via this delegate, and you provide the cell formatting and data in these protocol methods.
I'm not sure what you mean with "while my UITableView is loading". Do you mean while it is reloading data from the data source ? Because the UITableView is not involved any loading (and has no member "loading".
If you do [myTableView reloadData] then it is querying its dataSource. See the documentation of UITableViewDataSource protocol.
So YOU are responsible for loading data and then informing the table view that something in the data source has changed, and thus you should know when you are still loading data for your data source implementation :-)

Access Tableview Cell in some other methods

How to access a table view cell in some other user defined methods other than those predefined methods for tableview???
Plz help...
Thanx in advance...
for that you have to take the cell as global variable and acess it anywhere.
But remember untill you call the tableview reload method no change is gonna reflect.
So I suggest better use the cell in predefined delegate methods rather than trying to experiment (which can cause problem in consistency).
Happy Coding...