Getting the self.tableview indexpath from UISearchDisplayController tableView indexpath
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
add a comment |
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
add a comment |
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
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
iphone objective-c cocoa-touch uitableview
edited Jun 30 '11 at 14:08
randomor
asked Jun 29 '11 at 22:07
randomorrandomor
2,56432858
2,56432858
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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.
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
add a comment |
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.
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
add a comment |
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];
}
add a comment |
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
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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];
}
add a comment |
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];
}
add a comment |
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];
}
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];
}
answered Jun 30 '11 at 14:24
randomorrandomor
2,56432858
2,56432858
add a comment |
add a comment |
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
}
add a comment |
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
}
add a comment |
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
}
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
}
answered Jan 1 at 7:54
Satnam SyncSatnam Sync
1,2791227
1,2791227
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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