Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-28-2008, 02:10 PM   #1 (permalink)
Registered Member
 
Join Date: May 2008
Posts: 44
mademo is an unknown quantity at this point
Default Table cell refresh through timer

Hi all,

I'm doing something and haven't been able to make it work properly yet. This is what I do: I have a TableViewController managing a table which contains text labels that I'd like to periodically refresh to reflect some new text. Since the text of the label is supposed to change periodically, I'd like the new text showing up in each cell of the table periodically.

To this purpose I start a timer inside the initWithStyle method of the UITableViewController implementation like this:

<code>
timer = [NSTimer scheduledTimerWithTimeInterval1.0) target:self
selector:@selector(update userInfo:nil repeats:YES];
</code>

where update is something like this:

<code>
- (void)updateid)sender {

if (cntDeb == 0) cntDeb = 1;
else cntDeb = 0;

for (CellWrapper *element in displayList) {

if (cntDeb == 0)
element.textOfLabel = @"TEST AA";
else
element.textOfLabel = @"TEST BB";
}

}
</code>

I'm expecting to see the table cell label text flipping between TEST AA and TEST BB every second.
However, this doesn't happen and the table just displays the default text (neither TEST AA or TEST BB). The strange thing is that the cell's label flips between TEST AA and TEST BB after I drag the table with my finger up or down the screen. Only in this way I see the labels changing but not if I don't touch the screen.

Any ideas?
Thanks.
mademo is offline   Reply With Quote
Old 05-28-2008, 02:28 PM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 298
javid.alimohideen is an unknown quantity at this point
Default Re: Table cell refresh through timer

Trying refreshing the table data inside the timer

Code:
[self reloadData]; // if you have subclassed UITableView else [myTableView reloadData];
javid.alimohideen is offline   Reply With Quote
Old 05-28-2008, 04:06 PM   #3 (permalink)
Registered Member
 
Join Date: May 2008
Posts: 44
mademo is an unknown quantity at this point
Default Re: Table cell refresh through timer

great thanks!
mademo is offline   Reply With Quote
Old 05-28-2008, 05:44 PM   #4 (permalink)
Registered Member
 
Join Date: May 2008
Posts: 44
mademo is an unknown quantity at this point
Default Re: Table cell refresh through timer

hmmm, it seems to work but after a couple of minutes the program on the simulator crashes because of an uncaught exception.
mademo is offline   Reply With Quote
Old 05-29-2008, 09:13 AM   #5 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 298
javid.alimohideen is an unknown quantity at this point
Default Re: Table cell refresh through timer

Maybe the refresh timer is faster than the animation time. You can try calling view change method after the animation did finish. I don't have access to the exact method names but the
pseudo code would be :

Code:
 -(void) swapView {
    //Swap your views here, just maintain the current Index so you can get the view and
   // transition views for currIndex with currIndex + 1
}

-(void) animationDidFinish // this is a made up name but I am very sure a method for this exists{
   [self swapView];
}
Hope it works
javid.alimohideen is offline   Reply With Quote
Old 05-29-2008, 04:29 PM   #6 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
scottiphone is on a distinguished road
Default Re: Table cell refresh through timer

You could set the timer to not repeat and then after you've completed your action set it again (with no repeat) so you're not at the mercy of it getting way out of sync.

If it's running for awhile and then crashes it could also mean you're not releasing objects (memory fills up, set debug at memory warning to app) or have an object that is released (possibly autoreleased)
scottiphone is offline   Reply With Quote
Old 06-01-2008, 01:43 PM   #7 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 420
jeff_lamarche is an unknown quantity at this point
Send a message via AIM to jeff_lamarche Send a message via Yahoo to jeff_lamarche
Default Re: Table cell refresh through timer

Unless the data that is changing is outside of your control, this is the correct way to handle it. If YOU are changing the data, YOU should tell the table to reload its data when you change it. This is inefficient, and you really need to be concerned with efficiency when coding for the iPhone.

Also, this:

Code:
element.textOfLabel = @"TEST AA";
is probably not what you really want. I think what you probably mean is:

Code:
[element.textOfLabel isEqualToString:@"TEST AA"];
Objective-C does not allow overriding operators, so your comparison is a pointer comparison, and since you are creating a new constant, you will never be passed in a value that equals it.

You might also want to consider defining those pointers outside of your loop, probably as static, so you're not allocating new stack variables for every object in displayList.

Also, since these are UI elements, why not set a tag and look at that, rather than doing costly string comparisons? Comparing two ints is an order of magnitude more efficient than comparing NSString objects.
__________________
Check out my iPhone Dev Blog
You can send me e-mail at my forum username at mac dot com.
jeff_lamarche is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SMS balloon cell?? javid.alimohideen iPhone SDK Development 23 04-02-2010 08:48 AM
UITableViewCell height set at cell creation Cander iPhone SDK Development 8 10-22-2008 08:54 AM
Table view aa233 iPhone SDK Development 1 07-10-2008 05:11 PM
Easily customize table cell. pendraggon87 iPhone SDK Development 4 07-04-2008 07:06 AM
Creating a Timer? Nitrex88 iPhone SDK Development 2 05-25-2008 01:46 AM


» Advertisements
» Online Users: 332
4 members and 328 guests
guusleijsten, HowEver, LEARN2MAKE, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:42 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0