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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 02-04-2010, 05:17 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 2
Default UITextField in Custom UITableViewCell Not Updating

So I have a View where users can modify information about a company, the view works great the first time to click on a company, when you close the view (Using Navigation to go back), and click on another company.. the view comes up with all the same data.. I've already added a [self.tableView reloadData]; to the viewWillAppear and that doesn't seem to fix it.. Only way I can fix it, is to NOT reuse cells.. See code not working below, then the modified code that works.. can anyone explain this to me? I think it's a bad idea to NOT reuse the cells.... Any help would be greatly appreciated..

Code:
#define LABEL ((UILabel *)[cell viewWithTag:101])
#define DATA ((UITextField *)[cell viewWithTag:102])

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"BaseEditingCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"BaseEditingCell" owner:self options:nil] lastObject];
    }	
	
	[DATA setKeyboardType:UIKeyboardTypeDefault];
	switch(indexPath.row)
	{
		case 0:
			[LABEL setText:@"Company Name"];
			[DATA setText:selectedClient.name];
			[DATA setTag:1];
			break;
	}
	[DATA setNeedsDisplay];
	[cell setNeedsDisplay];
    
    // Set up the cell...
	
    return cell;
}
What DOES work is this:
Code:
#define LABEL ((UILabel *)[cell viewWithTag:101])
#define DATA ((UITextField *)[cell viewWithTag:102])

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        UITableViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"BaseEditingCell" owner:self options:nil] lastObject];
    	
	
	[DATA setKeyboardType:UIKeyboardTypeDefault];
	switch(indexPath.row)
	{
		case 0:
			[LABEL setText:@"Company Name"];
			[DATA setText:selectedClient.name];
			[DATA setTag:1];
			break;
	}
	[DATA setNeedsDisplay];
	[cell setNeedsDisplay];
    
    // Set up the cell...
	
    return cell;
}
rharby is offline   Reply With Quote
Old 02-04-2010, 05:58 PM   #2 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by rharby View Post
So I have a View where users can modify information about a company, the view works great the first time to click on a company, when you close the view (Using Navigation to go back), and click on another company.. the view comes up with all the same data.. I've already added a [self.tableView reloadData]; to the viewWillAppear and that doesn't seem to fix it.. Only way I can fix it, is to NOT reuse cells.. See code not working below, then the modified code that works.. can anyone explain this to me? I think it's a bad idea to NOT reuse the cells.... Any help would be greatly appreciated..
From what I can tell there can be several reasons for this behavior. Best would be to debug through the steps and see when your datasource is asked for the company name. it's possible that at the time of your calling of viewWillAppear the datasource still provides the old data.

If I could look at the code I could probably find the reason for this in 15 minutes or less.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 02-04-2010, 07:35 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 2
Default

Yeah, prior to posting I stepped through the whole thing, on the second time into the view, the selectedClient is set properly, the code runs which assigns it's text value to the UITextField.text property, but it still shows the old value...

Can I PM you the .m file?

Quote:
Originally Posted by Oliver Drobnik View Post
From what I can tell there can be several reasons for this behavior. Best would be to debug through the steps and see when your datasource is asked for the company name. it's possible that at the time of your calling of viewWillAppear the datasource still provides the old data.

If I could look at the code I could probably find the reason for this in 15 minutes or less.
rharby is offline   Reply With Quote
Old 02-05-2010, 03:17 AM   #4 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by rharby View Post
Yeah, prior to posting I stepped through the whole thing, on the second time into the view, the selectedClient is set properly, the code runs which assigns it's text value to the UITextField.text property, but it still shows the old value...

Can I PM you the .m file?
No, it would be better if we screen shared over Skype. I'm TheDrops.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 03-25-2010, 04:27 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 4
Default

If I could look at the code I could probably find the reason for this in 15 minutes or less.
__________________
To the world you may be one person,but to one person you may be the world.
gameboykk1 is offline   Reply With Quote
Reply

Bookmarks

Tags
uitableviewcell, uitextfield

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



» Advertisements
» Online Users: 241
15 members and 226 guests
ADY, AragornSG, CKAmike, Dani77, Dattee, Duncan C, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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