How to change specific element in row without reloading row in Objective-C?












0















I want to update a UiSwitch in a row in UITableView. I want to make it on and off with animation programmatically.



    NSIndexPath *indexPath = [[NSIndexPath indexPathForRow:0 inSection:lastSelectedCardSectionNumber] retain];
newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];
[cell.switch1 setOn:YES animated:YES];


but the above line not changes the state and I have to reload row which doesn't make UiSwitch state change with animation.





There is a view on top of the switch which will user taps on it to change the state of switch. but it should be change just in some situations. Therefore I don't allow user to change it I want to change it programmatically.










share|improve this question

























  • how are you triggering this? on didSelect of tableView?

    – hardik parmar
    Nov 24 '18 at 11:39











  • @hardikparmar I set a uiview on the switch to avoid switch state change by user. and when tapping on that view I someTimes(depends on some factors) change its state

    – Fattaneh Talebi
    Nov 24 '18 at 11:46













  • put the whole code of how you retrieved cell in the Touch action of view. Also, have you checked that the action you set up in the view is getting called?

    – hardik parmar
    Nov 24 '18 at 11:51











  • @hardikparmar Thanks. I updated my answer. yes it is called and when I write reload row method instead of setOn, it works but without animating the switch.

    – Fattaneh Talebi
    Nov 24 '18 at 11:57











  • check my answer.

    – hardik parmar
    Nov 24 '18 at 12:05
















0















I want to update a UiSwitch in a row in UITableView. I want to make it on and off with animation programmatically.



    NSIndexPath *indexPath = [[NSIndexPath indexPathForRow:0 inSection:lastSelectedCardSectionNumber] retain];
newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];
[cell.switch1 setOn:YES animated:YES];


but the above line not changes the state and I have to reload row which doesn't make UiSwitch state change with animation.





There is a view on top of the switch which will user taps on it to change the state of switch. but it should be change just in some situations. Therefore I don't allow user to change it I want to change it programmatically.










share|improve this question

























  • how are you triggering this? on didSelect of tableView?

    – hardik parmar
    Nov 24 '18 at 11:39











  • @hardikparmar I set a uiview on the switch to avoid switch state change by user. and when tapping on that view I someTimes(depends on some factors) change its state

    – Fattaneh Talebi
    Nov 24 '18 at 11:46













  • put the whole code of how you retrieved cell in the Touch action of view. Also, have you checked that the action you set up in the view is getting called?

    – hardik parmar
    Nov 24 '18 at 11:51











  • @hardikparmar Thanks. I updated my answer. yes it is called and when I write reload row method instead of setOn, it works but without animating the switch.

    – Fattaneh Talebi
    Nov 24 '18 at 11:57











  • check my answer.

    – hardik parmar
    Nov 24 '18 at 12:05














0












0








0








I want to update a UiSwitch in a row in UITableView. I want to make it on and off with animation programmatically.



    NSIndexPath *indexPath = [[NSIndexPath indexPathForRow:0 inSection:lastSelectedCardSectionNumber] retain];
newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];
[cell.switch1 setOn:YES animated:YES];


but the above line not changes the state and I have to reload row which doesn't make UiSwitch state change with animation.





There is a view on top of the switch which will user taps on it to change the state of switch. but it should be change just in some situations. Therefore I don't allow user to change it I want to change it programmatically.










share|improve this question
















I want to update a UiSwitch in a row in UITableView. I want to make it on and off with animation programmatically.



    NSIndexPath *indexPath = [[NSIndexPath indexPathForRow:0 inSection:lastSelectedCardSectionNumber] retain];
newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];
[cell.switch1 setOn:YES animated:YES];


but the above line not changes the state and I have to reload row which doesn't make UiSwitch state change with animation.





There is a view on top of the switch which will user taps on it to change the state of switch. but it should be change just in some situations. Therefore I don't allow user to change it I want to change it programmatically.







ios objective-c uiswitch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 12:08







Fattaneh Talebi

















asked Nov 24 '18 at 11:32









Fattaneh TalebiFattaneh Talebi

588823




588823













  • how are you triggering this? on didSelect of tableView?

    – hardik parmar
    Nov 24 '18 at 11:39











  • @hardikparmar I set a uiview on the switch to avoid switch state change by user. and when tapping on that view I someTimes(depends on some factors) change its state

    – Fattaneh Talebi
    Nov 24 '18 at 11:46













  • put the whole code of how you retrieved cell in the Touch action of view. Also, have you checked that the action you set up in the view is getting called?

    – hardik parmar
    Nov 24 '18 at 11:51











  • @hardikparmar Thanks. I updated my answer. yes it is called and when I write reload row method instead of setOn, it works but without animating the switch.

    – Fattaneh Talebi
    Nov 24 '18 at 11:57











  • check my answer.

    – hardik parmar
    Nov 24 '18 at 12:05



















  • how are you triggering this? on didSelect of tableView?

    – hardik parmar
    Nov 24 '18 at 11:39











  • @hardikparmar I set a uiview on the switch to avoid switch state change by user. and when tapping on that view I someTimes(depends on some factors) change its state

    – Fattaneh Talebi
    Nov 24 '18 at 11:46













  • put the whole code of how you retrieved cell in the Touch action of view. Also, have you checked that the action you set up in the view is getting called?

    – hardik parmar
    Nov 24 '18 at 11:51











  • @hardikparmar Thanks. I updated my answer. yes it is called and when I write reload row method instead of setOn, it works but without animating the switch.

    – Fattaneh Talebi
    Nov 24 '18 at 11:57











  • check my answer.

    – hardik parmar
    Nov 24 '18 at 12:05

















how are you triggering this? on didSelect of tableView?

– hardik parmar
Nov 24 '18 at 11:39





how are you triggering this? on didSelect of tableView?

– hardik parmar
Nov 24 '18 at 11:39













@hardikparmar I set a uiview on the switch to avoid switch state change by user. and when tapping on that view I someTimes(depends on some factors) change its state

– Fattaneh Talebi
Nov 24 '18 at 11:46







@hardikparmar I set a uiview on the switch to avoid switch state change by user. and when tapping on that view I someTimes(depends on some factors) change its state

– Fattaneh Talebi
Nov 24 '18 at 11:46















put the whole code of how you retrieved cell in the Touch action of view. Also, have you checked that the action you set up in the view is getting called?

– hardik parmar
Nov 24 '18 at 11:51





put the whole code of how you retrieved cell in the Touch action of view. Also, have you checked that the action you set up in the view is getting called?

– hardik parmar
Nov 24 '18 at 11:51













@hardikparmar Thanks. I updated my answer. yes it is called and when I write reload row method instead of setOn, it works but without animating the switch.

– Fattaneh Talebi
Nov 24 '18 at 11:57





@hardikparmar Thanks. I updated my answer. yes it is called and when I write reload row method instead of setOn, it works but without animating the switch.

– Fattaneh Talebi
Nov 24 '18 at 11:57













check my answer.

– hardik parmar
Nov 24 '18 at 12:05





check my answer.

– hardik parmar
Nov 24 '18 at 12:05












1 Answer
1






active

oldest

votes


















1














The problem is with how you are retrieving the cell. It should be:



newCell *cell = (newCell *)[self.tableView cellForRowAtIndexPath:indexPath];


not this:



newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];


The former gets the already existing instance of cell but the later one creates the new instance of the cell.






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',
    autoActivateHeartbeat: false,
    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%2f53457691%2fhow-to-change-specific-element-in-row-without-reloading-row-in-objective-c%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









    1














    The problem is with how you are retrieving the cell. It should be:



    newCell *cell = (newCell *)[self.tableView cellForRowAtIndexPath:indexPath];


    not this:



    newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];


    The former gets the already existing instance of cell but the later one creates the new instance of the cell.






    share|improve this answer






























      1














      The problem is with how you are retrieving the cell. It should be:



      newCell *cell = (newCell *)[self.tableView cellForRowAtIndexPath:indexPath];


      not this:



      newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];


      The former gets the already existing instance of cell but the later one creates the new instance of the cell.






      share|improve this answer




























        1












        1








        1







        The problem is with how you are retrieving the cell. It should be:



        newCell *cell = (newCell *)[self.tableView cellForRowAtIndexPath:indexPath];


        not this:



        newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];


        The former gets the already existing instance of cell but the later one creates the new instance of the cell.






        share|improve this answer















        The problem is with how you are retrieving the cell. It should be:



        newCell *cell = (newCell *)[self.tableView cellForRowAtIndexPath:indexPath];


        not this:



        newCell *cell = (newCell *)[self.myTableView dequeueReusableCellWithIdentifier:@"newCell" forIndexPath:indexPath];


        The former gets the already existing instance of cell but the later one creates the new instance of the cell.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 24 '18 at 12:09

























        answered Nov 24 '18 at 12:04









        hardik parmarhardik parmar

        687414




        687414
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457691%2fhow-to-change-specific-element-in-row-without-reloading-row-in-objective-c%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

            Wiesbaden

            Marschland

            Dieringhausen