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 11-23-2011, 03:14 PM   #1 (permalink)
Beginner iOS Dev
 
Join Date: Feb 2011
Location: Boston
Posts: 372
cityofangels is on a distinguished road
Default Having issue with UITextField and UITableViewCells

I have UITextField in my UITableViewCell in a UITableView. I have 11 cells total. When I enter text in a cell, and scroll the cell off the screen, that text is getting cleared.

It seems like maybe the cells are being dequed or deallocated? I need all the cells's textFields to be visible within this view at all times and there are only 11 so it doesn't be too much of an issue.
cityofangels is offline   Reply With Quote
Old 11-23-2011, 03:47 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 245
samurle is on a distinguished road
Default

Quote:
Originally Posted by cityofangels View Post
I have UITextField in my UITableViewCell in a UITableView. I have 11 cells total. When I enter text in a cell, and scroll the cell off the screen, that text is getting cleared.

It seems like maybe the cells are being dequed or deallocated? I need all the cells's textFields to be visible within this view at all times and there are only 11 so it doesn't be too much of an issue.
Are you tring to use UITableViewCell for storage? Because I don't think it works like that.
If something gets edited, you have to store it yourself.

Anything that gets added to a UITableViewCell may get re-used, so you have to make sure these fields
get cleared out before you use them.
samurle is offline   Reply With Quote
Old 11-23-2011, 03:51 PM   #3 (permalink)
Beginner iOS Dev
 
Join Date: Feb 2011
Location: Boston
Posts: 372
cityofangels is on a distinguished road
Default

This is the code I'm using. Is it because I don't have a datasource such as an array or something? I'm pulling the text initally from the childAppointmentDictionary if there is text from the server, otherwise the user enters text and I save it to an NSString. I'm also using ARC.

Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        CellIdentifier = @"textCell";
        VitalsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        switch (indexPath.row) {
            case 0:
                cell.vitalsLabel.text = @"Temperature";
                cell.textField.text = [self.childAppointmentDictionary objectForKey:@"temperature"];
                self.temperatureTextField = cell.textField;
                break;
            case 1:
                cell.vitalsLabel.text = @"Pulse";
                cell.textField.text = [self.childAppointmentDictionary objectForKey:@"pulse"];
                self.pulseTextField = cell.textField;
                break;
            default:
                break;
        }
        return cell;
    }
        
    - (void) textFieldDidEndEditing:(UITextField *)textField{
        if (textField == temperatureTextField){
            self.temperatureString = self.temperatureTextField.text;
        } 
        else if (textField == pulseTextField){
            self.pulseString = self.pulseTextField.text;
        }
    }
cityofangels is offline   Reply With Quote
Old 11-24-2011, 05:43 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 245
samurle is on a distinguished road
Default

Quote:
Originally Posted by cityofangels View Post
This is the code I'm using. Is it because I don't have a datasource such as an array or something? I'm pulling the text initally from the childAppointmentDictionary if there is text from the server, otherwise the user enters text and I save it to an NSString. I'm also using ARC.
The table cell is either being allocated new or being re-used.

This is the default code from the XCode template.

Code:
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
samurle 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



» Advertisements
» Online Users: 401
14 members and 387 guests
7twenty7, chiataytuday, Clouds, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, leostc, Murphy, QuantumDoja, sacha1996, Sami Gh
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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