Getting the self.tableview indexpath from UISearchDisplayController tableView indexpath












0















So I have a detail view that need to display information by getting a index integer caculated from the indexpath from the selected cell in self.tableview, I've been using the NSFetchedResultsController for the self.tableview too. I've also implemented a UISearchDisplayController to do search.



Question:
How do I convert the selected indexPath in the UISearchDisplayController tableview to the indexpath of the original self.tableview? Or do I need to set up a NSArray instance and loop through it to find out the index? What's the most efficient way to do it?



Here is the code:



-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
NSLog(@"display project details");
if (tableView == self.table) {
[parentController projectSelectedFromList:indexPath.row];
}else{
NSInteger index;
//what to put here? To get the indexPath of the self.table from search tableview
[parentController projectSelectedFromList:index];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}









share|improve this question





























    0















    So I have a detail view that need to display information by getting a index integer caculated from the indexpath from the selected cell in self.tableview, I've been using the NSFetchedResultsController for the self.tableview too. I've also implemented a UISearchDisplayController to do search.



    Question:
    How do I convert the selected indexPath in the UISearchDisplayController tableview to the indexpath of the original self.tableview? Or do I need to set up a NSArray instance and loop through it to find out the index? What's the most efficient way to do it?



    Here is the code:



    -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
    NSLog(@"display project details");
    if (tableView == self.table) {
    [parentController projectSelectedFromList:indexPath.row];
    }else{
    NSInteger index;
    //what to put here? To get the indexPath of the self.table from search tableview
    [parentController projectSelectedFromList:index];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }









    share|improve this question



























      0












      0








      0








      So I have a detail view that need to display information by getting a index integer caculated from the indexpath from the selected cell in self.tableview, I've been using the NSFetchedResultsController for the self.tableview too. I've also implemented a UISearchDisplayController to do search.



      Question:
      How do I convert the selected indexPath in the UISearchDisplayController tableview to the indexpath of the original self.tableview? Or do I need to set up a NSArray instance and loop through it to find out the index? What's the most efficient way to do it?



      Here is the code:



      -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
      NSLog(@"display project details");
      if (tableView == self.table) {
      [parentController projectSelectedFromList:indexPath.row];
      }else{
      NSInteger index;
      //what to put here? To get the indexPath of the self.table from search tableview
      [parentController projectSelectedFromList:index];
      }
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
      }









      share|improve this question
















      So I have a detail view that need to display information by getting a index integer caculated from the indexpath from the selected cell in self.tableview, I've been using the NSFetchedResultsController for the self.tableview too. I've also implemented a UISearchDisplayController to do search.



      Question:
      How do I convert the selected indexPath in the UISearchDisplayController tableview to the indexpath of the original self.tableview? Or do I need to set up a NSArray instance and loop through it to find out the index? What's the most efficient way to do it?



      Here is the code:



      -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
      NSLog(@"display project details");
      if (tableView == self.table) {
      [parentController projectSelectedFromList:indexPath.row];
      }else{
      NSInteger index;
      //what to put here? To get the indexPath of the self.table from search tableview
      [parentController projectSelectedFromList:index];
      }
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
      }






      iphone objective-c cocoa-touch uitableview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 30 '11 at 14:08







      randomor

















      asked Jun 29 '11 at 22:07









      randomorrandomor

      2,56432858




      2,56432858
























          4 Answers
          4






          active

          oldest

          votes


















          3














          Assuming no duplicates,



          id selectedObject = [searchArray objectAtIndex:indexPath.row];
          index = [sourceArray indexOfObject:selectedObject];


          Idea is pretty simple. Get the selected object of your search array as it will map directly to the index path's row. Then search for the object's index within the source or master array. This should give you the index you want.






          share|improve this answer
























          • Thanks. That's basically what I did. The trick is finding out about the indexPathForObject method for NSFetchedResultsController. :)

            – randomor
            Jun 30 '11 at 14:25



















          0














          Look at what you have you got in tableView:cellForRowAtIndexPath: of your tableView data source (usually the tableViewController object). Assuming you do a similar check on whether you are using the standard tableView or the search tableView there - and if you're not, then you're search filter surely won't be effective - you just need to have analogous code in the your tableView:didSelectRowAtIndexPath:.



          If I'm missing the point here then apologies... and you might need to say a bit more in your question.






          share|improve this answer
























          • Thanks for the input, but I did get my search tableview working and is just looking for a way to convert the selected indexPath in the search tableview to the indexpath of the original self.tableview. :)

            – randomor
            Jun 30 '11 at 14:05



















          0














          I found out the solution:



          -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
          NSLog(@"display project details");
          if (tableView == self.table) {
          [parentController projectSelectedFromList:indexPath.row];
          NSLog(@"indexpath at orignal tableview is: %@", [indexPath description]);
          }else{
          NSIndexPath *indexPathForOriginal = [resultsController indexPathForObject: [self.filteredResults objectAtIndex:indexPath.row]];
          NSInteger index = indexPathForOriginal.row;
          [parentController projectSelectedFromList:index];
          NSLog(@"indexpath at search tableview is: %@", [indexPathForOriginal description]);

          }
          [tableView deselectRowAtIndexPath:indexPath animated:YES];


          }






          share|improve this answer































            0














            Swift version of @Deepak Danduprolu answer:



            override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            var selectedObject = searchedArray[indexPath.row]
            var index = OrignalArray.index(of: selectedObject)
            print("index", index) // This will give you index of selected array from the original array
            }





            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%2f6527841%2fgetting-the-self-tableview-indexpath-from-uisearchdisplaycontroller-tableview-in%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              Assuming no duplicates,



              id selectedObject = [searchArray objectAtIndex:indexPath.row];
              index = [sourceArray indexOfObject:selectedObject];


              Idea is pretty simple. Get the selected object of your search array as it will map directly to the index path's row. Then search for the object's index within the source or master array. This should give you the index you want.






              share|improve this answer
























              • Thanks. That's basically what I did. The trick is finding out about the indexPathForObject method for NSFetchedResultsController. :)

                – randomor
                Jun 30 '11 at 14:25
















              3














              Assuming no duplicates,



              id selectedObject = [searchArray objectAtIndex:indexPath.row];
              index = [sourceArray indexOfObject:selectedObject];


              Idea is pretty simple. Get the selected object of your search array as it will map directly to the index path's row. Then search for the object's index within the source or master array. This should give you the index you want.






              share|improve this answer
























              • Thanks. That's basically what I did. The trick is finding out about the indexPathForObject method for NSFetchedResultsController. :)

                – randomor
                Jun 30 '11 at 14:25














              3












              3








              3







              Assuming no duplicates,



              id selectedObject = [searchArray objectAtIndex:indexPath.row];
              index = [sourceArray indexOfObject:selectedObject];


              Idea is pretty simple. Get the selected object of your search array as it will map directly to the index path's row. Then search for the object's index within the source or master array. This should give you the index you want.






              share|improve this answer













              Assuming no duplicates,



              id selectedObject = [searchArray objectAtIndex:indexPath.row];
              index = [sourceArray indexOfObject:selectedObject];


              Idea is pretty simple. Get the selected object of your search array as it will map directly to the index path's row. Then search for the object's index within the source or master array. This should give you the index you want.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 30 '11 at 14:21









              Deepak DanduproluDeepak Danduprolu

              43.2k1194104




              43.2k1194104













              • Thanks. That's basically what I did. The trick is finding out about the indexPathForObject method for NSFetchedResultsController. :)

                – randomor
                Jun 30 '11 at 14:25



















              • Thanks. That's basically what I did. The trick is finding out about the indexPathForObject method for NSFetchedResultsController. :)

                – randomor
                Jun 30 '11 at 14:25

















              Thanks. That's basically what I did. The trick is finding out about the indexPathForObject method for NSFetchedResultsController. :)

              – randomor
              Jun 30 '11 at 14:25





              Thanks. That's basically what I did. The trick is finding out about the indexPathForObject method for NSFetchedResultsController. :)

              – randomor
              Jun 30 '11 at 14:25













              0














              Look at what you have you got in tableView:cellForRowAtIndexPath: of your tableView data source (usually the tableViewController object). Assuming you do a similar check on whether you are using the standard tableView or the search tableView there - and if you're not, then you're search filter surely won't be effective - you just need to have analogous code in the your tableView:didSelectRowAtIndexPath:.



              If I'm missing the point here then apologies... and you might need to say a bit more in your question.






              share|improve this answer
























              • Thanks for the input, but I did get my search tableview working and is just looking for a way to convert the selected indexPath in the search tableview to the indexpath of the original self.tableview. :)

                – randomor
                Jun 30 '11 at 14:05
















              0














              Look at what you have you got in tableView:cellForRowAtIndexPath: of your tableView data source (usually the tableViewController object). Assuming you do a similar check on whether you are using the standard tableView or the search tableView there - and if you're not, then you're search filter surely won't be effective - you just need to have analogous code in the your tableView:didSelectRowAtIndexPath:.



              If I'm missing the point here then apologies... and you might need to say a bit more in your question.






              share|improve this answer
























              • Thanks for the input, but I did get my search tableview working and is just looking for a way to convert the selected indexPath in the search tableview to the indexpath of the original self.tableview. :)

                – randomor
                Jun 30 '11 at 14:05














              0












              0








              0







              Look at what you have you got in tableView:cellForRowAtIndexPath: of your tableView data source (usually the tableViewController object). Assuming you do a similar check on whether you are using the standard tableView or the search tableView there - and if you're not, then you're search filter surely won't be effective - you just need to have analogous code in the your tableView:didSelectRowAtIndexPath:.



              If I'm missing the point here then apologies... and you might need to say a bit more in your question.






              share|improve this answer













              Look at what you have you got in tableView:cellForRowAtIndexPath: of your tableView data source (usually the tableViewController object). Assuming you do a similar check on whether you are using the standard tableView or the search tableView there - and if you're not, then you're search filter surely won't be effective - you just need to have analogous code in the your tableView:didSelectRowAtIndexPath:.



              If I'm missing the point here then apologies... and you might need to say a bit more in your question.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 29 '11 at 23:24









              ObliquelyObliquely

              5,57122347




              5,57122347













              • Thanks for the input, but I did get my search tableview working and is just looking for a way to convert the selected indexPath in the search tableview to the indexpath of the original self.tableview. :)

                – randomor
                Jun 30 '11 at 14:05



















              • Thanks for the input, but I did get my search tableview working and is just looking for a way to convert the selected indexPath in the search tableview to the indexpath of the original self.tableview. :)

                – randomor
                Jun 30 '11 at 14:05

















              Thanks for the input, but I did get my search tableview working and is just looking for a way to convert the selected indexPath in the search tableview to the indexpath of the original self.tableview. :)

              – randomor
              Jun 30 '11 at 14:05





              Thanks for the input, but I did get my search tableview working and is just looking for a way to convert the selected indexPath in the search tableview to the indexpath of the original self.tableview. :)

              – randomor
              Jun 30 '11 at 14:05











              0














              I found out the solution:



              -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
              NSLog(@"display project details");
              if (tableView == self.table) {
              [parentController projectSelectedFromList:indexPath.row];
              NSLog(@"indexpath at orignal tableview is: %@", [indexPath description]);
              }else{
              NSIndexPath *indexPathForOriginal = [resultsController indexPathForObject: [self.filteredResults objectAtIndex:indexPath.row]];
              NSInteger index = indexPathForOriginal.row;
              [parentController projectSelectedFromList:index];
              NSLog(@"indexpath at search tableview is: %@", [indexPathForOriginal description]);

              }
              [tableView deselectRowAtIndexPath:indexPath animated:YES];


              }






              share|improve this answer




























                0














                I found out the solution:



                -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
                NSLog(@"display project details");
                if (tableView == self.table) {
                [parentController projectSelectedFromList:indexPath.row];
                NSLog(@"indexpath at orignal tableview is: %@", [indexPath description]);
                }else{
                NSIndexPath *indexPathForOriginal = [resultsController indexPathForObject: [self.filteredResults objectAtIndex:indexPath.row]];
                NSInteger index = indexPathForOriginal.row;
                [parentController projectSelectedFromList:index];
                NSLog(@"indexpath at search tableview is: %@", [indexPathForOriginal description]);

                }
                [tableView deselectRowAtIndexPath:indexPath animated:YES];


                }






                share|improve this answer


























                  0












                  0








                  0







                  I found out the solution:



                  -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
                  NSLog(@"display project details");
                  if (tableView == self.table) {
                  [parentController projectSelectedFromList:indexPath.row];
                  NSLog(@"indexpath at orignal tableview is: %@", [indexPath description]);
                  }else{
                  NSIndexPath *indexPathForOriginal = [resultsController indexPathForObject: [self.filteredResults objectAtIndex:indexPath.row]];
                  NSInteger index = indexPathForOriginal.row;
                  [parentController projectSelectedFromList:index];
                  NSLog(@"indexpath at search tableview is: %@", [indexPathForOriginal description]);

                  }
                  [tableView deselectRowAtIndexPath:indexPath animated:YES];


                  }






                  share|improve this answer













                  I found out the solution:



                  -(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
                  NSLog(@"display project details");
                  if (tableView == self.table) {
                  [parentController projectSelectedFromList:indexPath.row];
                  NSLog(@"indexpath at orignal tableview is: %@", [indexPath description]);
                  }else{
                  NSIndexPath *indexPathForOriginal = [resultsController indexPathForObject: [self.filteredResults objectAtIndex:indexPath.row]];
                  NSInteger index = indexPathForOriginal.row;
                  [parentController projectSelectedFromList:index];
                  NSLog(@"indexpath at search tableview is: %@", [indexPathForOriginal description]);

                  }
                  [tableView deselectRowAtIndexPath:indexPath animated:YES];


                  }







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 30 '11 at 14:24









                  randomorrandomor

                  2,56432858




                  2,56432858























                      0














                      Swift version of @Deepak Danduprolu answer:



                      override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                      var selectedObject = searchedArray[indexPath.row]
                      var index = OrignalArray.index(of: selectedObject)
                      print("index", index) // This will give you index of selected array from the original array
                      }





                      share|improve this answer




























                        0














                        Swift version of @Deepak Danduprolu answer:



                        override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                        var selectedObject = searchedArray[indexPath.row]
                        var index = OrignalArray.index(of: selectedObject)
                        print("index", index) // This will give you index of selected array from the original array
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          Swift version of @Deepak Danduprolu answer:



                          override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                          var selectedObject = searchedArray[indexPath.row]
                          var index = OrignalArray.index(of: selectedObject)
                          print("index", index) // This will give you index of selected array from the original array
                          }





                          share|improve this answer













                          Swift version of @Deepak Danduprolu answer:



                          override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                          var selectedObject = searchedArray[indexPath.row]
                          var index = OrignalArray.index(of: selectedObject)
                          print("index", index) // This will give you index of selected array from the original array
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 1 at 7:54









                          Satnam SyncSatnam Sync

                          1,2791227




                          1,2791227






























                              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%2f6527841%2fgetting-the-self-tableview-indexpath-from-uisearchdisplaycontroller-tableview-in%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

                              Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                              Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                              A Topological Invariant for $pi_3(U(n))$