Save temporary values deleted by reloadData in a UITableView











up vote
0
down vote

favorite












I have a simple project with UITableViewCell, inside the Cell I have a UITextField, In my case I am creating rows of a table dynamically, ie:



When I call function 'AddField' There is a counter that is responsible for storing the number of rows that the table must have.



-(void)AddField{

numberOfRows++;
[tableView reloadData];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return numberOfRows;
}


So, if I type something in the first text field and then call the function to add more rows in the table, the row is added, another text field appear (leaving two), but the text entered in the first text field disappears due the command reloadData.



I Need help find the best way around this problem, any suggestions?










share|improve this question
























  • have you considered using insertRowsAtIndexPaths:withRowAnimation: rather than handling it yourself?
    – chetem
    May 19 '14 at 17:35












  • I will try this soon!
    – user3613119
    May 19 '14 at 18:20















up vote
0
down vote

favorite












I have a simple project with UITableViewCell, inside the Cell I have a UITextField, In my case I am creating rows of a table dynamically, ie:



When I call function 'AddField' There is a counter that is responsible for storing the number of rows that the table must have.



-(void)AddField{

numberOfRows++;
[tableView reloadData];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return numberOfRows;
}


So, if I type something in the first text field and then call the function to add more rows in the table, the row is added, another text field appear (leaving two), but the text entered in the first text field disappears due the command reloadData.



I Need help find the best way around this problem, any suggestions?










share|improve this question
























  • have you considered using insertRowsAtIndexPaths:withRowAnimation: rather than handling it yourself?
    – chetem
    May 19 '14 at 17:35












  • I will try this soon!
    – user3613119
    May 19 '14 at 18:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a simple project with UITableViewCell, inside the Cell I have a UITextField, In my case I am creating rows of a table dynamically, ie:



When I call function 'AddField' There is a counter that is responsible for storing the number of rows that the table must have.



-(void)AddField{

numberOfRows++;
[tableView reloadData];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return numberOfRows;
}


So, if I type something in the first text field and then call the function to add more rows in the table, the row is added, another text field appear (leaving two), but the text entered in the first text field disappears due the command reloadData.



I Need help find the best way around this problem, any suggestions?










share|improve this question















I have a simple project with UITableViewCell, inside the Cell I have a UITextField, In my case I am creating rows of a table dynamically, ie:



When I call function 'AddField' There is a counter that is responsible for storing the number of rows that the table must have.



-(void)AddField{

numberOfRows++;
[tableView reloadData];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return numberOfRows;
}


So, if I type something in the first text field and then call the function to add more rows in the table, the row is added, another text field appear (leaving two), but the text entered in the first text field disappears due the command reloadData.



I Need help find the best way around this problem, any suggestions?







objective-c uitableview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 6:46









Cœur

17k9102140




17k9102140










asked May 19 '14 at 17:05









user3613119

495




495












  • have you considered using insertRowsAtIndexPaths:withRowAnimation: rather than handling it yourself?
    – chetem
    May 19 '14 at 17:35












  • I will try this soon!
    – user3613119
    May 19 '14 at 18:20


















  • have you considered using insertRowsAtIndexPaths:withRowAnimation: rather than handling it yourself?
    – chetem
    May 19 '14 at 17:35












  • I will try this soon!
    – user3613119
    May 19 '14 at 18:20
















have you considered using insertRowsAtIndexPaths:withRowAnimation: rather than handling it yourself?
– chetem
May 19 '14 at 17:35






have you considered using insertRowsAtIndexPaths:withRowAnimation: rather than handling it yourself?
– chetem
May 19 '14 at 17:35














I will try this soon!
– user3613119
May 19 '14 at 18:20




I will try this soon!
– user3613119
May 19 '14 at 18:20












1 Answer
1






active

oldest

votes

















up vote
0
down vote















  1. Have a Mutable array to store all the typed values.



    [self.myMutableArray addObject:cell.textField.text];




  2. In cell for Row at index path, get the text and set it back to the text field.



    cell.textField.text = self.myMutableArray[indexPath.row]








share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23743385%2fsave-temporary-values-deleted-by-reloaddata-in-a-uitableview%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote















    1. Have a Mutable array to store all the typed values.



      [self.myMutableArray addObject:cell.textField.text];




    2. In cell for Row at index path, get the text and set it back to the text field.



      cell.textField.text = self.myMutableArray[indexPath.row]








    share|improve this answer

























      up vote
      0
      down vote















      1. Have a Mutable array to store all the typed values.



        [self.myMutableArray addObject:cell.textField.text];




      2. In cell for Row at index path, get the text and set it back to the text field.



        cell.textField.text = self.myMutableArray[indexPath.row]








      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote











        1. Have a Mutable array to store all the typed values.



          [self.myMutableArray addObject:cell.textField.text];




        2. In cell for Row at index path, get the text and set it back to the text field.



          cell.textField.text = self.myMutableArray[indexPath.row]








        share|improve this answer














        1. Have a Mutable array to store all the typed values.



          [self.myMutableArray addObject:cell.textField.text];




        2. In cell for Row at index path, get the text and set it back to the text field.



          cell.textField.text = self.myMutableArray[indexPath.row]









        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 19 '14 at 17:44









        Naveen Prasad R

        1,84911016




        1,84911016






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23743385%2fsave-temporary-values-deleted-by-reloaddata-in-a-uitableview%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python