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-14-2011, 07:15 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default Custom UITableviewcell - UITextfield data

I have a custom UITableview cell in which i have a UITextfield. The user entersdata in the textfield. When the user leaves the app i am saving the information to an array. In the viewDidDisappea method i am doing this. But my array always shows null. user entered data is not persisted. How will i do this
vikinara is offline   Reply With Quote
Old 05-14-2011, 07:21 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Show us how you are saving the information to the array and then how you are saving the array so you can retrieve it later.
Domele is offline   Reply With Quote
Old 05-14-2011, 07:47 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Show us how you are saving the information to the array and then how you are saving the array so you can retrieve it later.
Code:
addressArray = [[[NSMutableArray alloc] init]autorelease];
if (![addresscell.txtStreet.text length] == 0){
        [addressArray addObject:addresscell.txtStreet.text];
        
    
    }else{
        
        [addressArray addObject:[NSNull null]];
    }
    if (![addresscell.txtZip.text length] == 0){
        [addressArray addObject:addresscell.txtZip.text];
    }else{
        
        [addressArray addObject:[NSNull null]];
    }
    if (![addresscell.txtState.text length] == 0){
        
        [addressArray addObject:addresscell.txtState.text];
    }else{
        
        [addressArray addObject:[NSNull null]];
    }if (![addresscell.txtCity.text length] == 0){
        [addressArray addObject:addresscell.txtCity.text];
        
        NSLog(@"City:%@",city);
    }else{
        
        [addressArray addObject:[NSNull null]];
    }
    [addressArray addObject:[NSNull null]];
vikinara is offline   Reply With Quote
Old 05-14-2011, 07:51 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Right, how are you saving the array so you can access it later?
Domele is offline   Reply With Quote
Old 05-14-2011, 07:55 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Right, how are you saving the array so you can access it later?
The problem is not with the array. The UITextfield data in the Custom UItableviewcell. The data in UItextfield is not saved in the array. It always returns null value, if i scroll.
vikinara is offline   Reply With Quote
Old 05-14-2011, 07:59 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Well you are auto releasing it which means it'll be destroyed at a later time. And you said that you are saving the array when the user leaves the app, where are you doing that?
Domele is offline   Reply With Quote
Old 05-14-2011, 08:07 PM   #7 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Well you are auto releasing it which means it'll be destroyed at a later time. And you said that you are saving the array when the user leaves the app, where are you doing that?
ViewDidDisappear method. But the data in my textfields are not persisted. how can i persist it.
vikinara is offline   Reply With Quote
Old 05-14-2011, 08:15 PM   #8 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Do you mean that when you scroll down far enough to push the UITextFields out of view, when you scroll back up, the text in the fields are gone? If so, you need to store that data in array, don't auto release it otherwise it will get destroyed, and set it in cellForRowAtIndexPath.
Domele is offline   Reply With Quote
Old 05-14-2011, 08:22 PM   #9 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Do you mean that when you scroll down far enough to push the UITextFields out of view, when you scroll back up, the text in the fields are gone? If so, you need to store that data in array, don't auto release it otherwise it will get destroyed, and set it in cellForRowAtIndexPath.
I have two issues. One is data is not persisted in the scroll, as well as even if after the data is entered only the cell that is visible on the screen is saved. All the textfields show only empty data.
vikinara is offline   Reply With Quote
Old 05-15-2011, 04:02 AM   #10 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by vikinara View Post
I have two issues. One is data is not persisted in the scroll, as well as even if after the data is entered only the cell that is visible on the screen is saved. All the textfields show only empty data.
ehm......we already explained you that you must not autorelease the array...
__________________
dany_dev is offline   Reply With Quote
Old 05-15-2011, 05:33 PM   #11 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
ehm......we already explained you that you must not autorelease the array...
I have a UITableViewController with some custom cells that hold some UITextFields so the user should enter some values on them and then tap on the done button up in the navigation bar to save all the information. The problem is, if the user scrolls down and then tap on the done button the information on the text fields that is out of sight doesn't get saved. I understand the why, the UITableViewCell's that are out of sight get unallocated, so when the user saves there is basically nothing on them although if the user scroll back the information remains on the fields.

I used the array to save but same behaviour exists.

So my question is how can I retrieve the content of the text fields for saving it? [quote]
vikinara is offline   Reply With Quote
Old 05-15-2011, 07:27 PM   #12 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Add a tag value to your textfields. Make your view controller comply to the UITextField protocol, add the method that says something like textDidChange and in that method, check the tag value to figure out which textfield is sending the message, then save the text from that textfield somewhere.
Domele is offline   Reply With Quote
Old 05-16-2011, 08:16 PM   #13 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Code:
static NSString *CellIdentifier1 = @"Cell";
        GeneralInfocell *cell = (GeneralInfocell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
        
        [[NSBundle mainBundle] loadNibNamed:@"GeneralInfocell" owner:self options:nil];
        cell = addresscell;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
         addresscell.txtStreet.delegate = self;
        addresscell.txtStreet.font = [UIFont fontWithName:@"Arial" size:14];
        addresscell.txtStreet.keyboardType = UIKeyboardTypeDefault;
        addresscell.txtStreet.returnKeyType = UIReturnKeyNext;
        addresscell.txtStreet.backgroundColor = [UIColor whiteColor];
        addresscell.txtStreet.autocorrectionType = UITextAutocorrectionTypeNo;
       addresscell. txtStreet.autocapitalizationType = UITextAutocapitalizationTypeNone;
      addresscell. txtStreet.textAlignment = UITextAlignmentLeft;
        addresscell.txtStreet.textColor = [UIColor blackColor];
        
        addresscell.txtStreet.tag = kViewTag;

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    if([addresscell.txtStreet viewWithTag:kViewTag]){
    
    UILabel *label = [NSString stringWithFormat:@"%@",[addresscell.txtCity text]];
        
        NSLog(@"label:%@",label);
    }
I tried it. But no luck.
vikinara is offline   Reply With Quote
Old 05-16-2011, 08:19 PM   #14 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Put an NSLog before the if statement, see if it fires. Also, did you declare "addresscell" as an ivar?

Edit: Sorry I missed it. You need to do this:

Code:
if(textField.tag == kViewTag){
    UILabel *label = [NSString stringWithFormat:@"%@",[textField text]];
    NSLog(@"label:%@",label);
}

Last edited by Domele; 05-16-2011 at 08:25 PM.
Domele is offline   Reply With Quote
Old 05-16-2011, 08:39 PM   #15 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Put an NSLog before the if statement, see if it fires. Also, did you declare "addresscell" as an ivar?
[quote] Yes I did. GeneralInfocell *addresscell;

I get only "label:" in my log.

I change the if condition like this.
if([textField viewWithTag:kViewTag]){

UILabel *label = [NSString stringWithFormat:@"%@",[addresscell.txtStreet text]];

NSLog(@"label:%@",label);
}

it fired still i get no value in log.
could you please help me.

Last edited by vikinara; 05-16-2011 at 08:54 PM.
vikinara is offline   Reply With Quote
Old 05-16-2011, 08:41 PM   #16 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

I edited my post if you didn't see it.
Domele is offline   Reply With Quote
Old 05-16-2011, 08:56 PM   #17 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

[quote=vikinara;335547]
Quote:
Yes I did. GeneralInfocell *addresscell;

I get only "label:" in my log.

I change the if condition like this.
if([textField viewWithTag:kViewTag]){

UILabel *label = [NSString stringWithFormat:@"%@",[addresscell.txtStreet text]];

NSLog(@"label:%@",label);
}

it fired still i get no value in log.
could you please help me.

I changed the code like below. I got the textfield value.
- (void)textFieldDidEndEditingUITextField *)textField {

if([textField viewWithTag:kViewTag]){

NSString *label = textField.text;

NSLog(@"label:%@",label);
}


I need to save the value in the array now. But how will i retrieve it from teh array.
vikinara is offline   Reply With Quote
Old 05-16-2011, 09:13 PM   #18 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Put an NSLog before the if statement, see if it fires. Also, did you declare "addresscell" as an ivar?

Edit: Sorry I missed it. You need to do this:

Code:
if(textField.tag == kViewTag){
    UILabel *label = [NSString stringWithFormat:@"%@",[textField text]];
    NSLog(@"label:%@",label);
}
Just now i saw it. Thank u. It worked.

Last edited by vikinara; 05-17-2011 at 11:16 AM.
vikinara is offline   Reply With Quote
Reply

Bookmarks

Tags
customcell, 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: 367
6 members and 361 guests
doffing81, dre, iOS.Lover, Kirkout, MikaelBartlett, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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