PDA

View Full Version : Help with some Logic in "Search Bar"




Nekbeth
Mar 31, 2011, 06:25 PM
Hi, I'm implementing a Search bar, everything is ready except I need to copy all of my Dictionary Titles to an array called listOfRecipes. I already have to path to access them, which is the following:
NSUInteger section = [indexPath section];

NSUInteger row = [indexPath row];





NSString *key = [keys objectAtIndex:section];

NSArray *nameSection = [names objectForKey:key];

Something = [[nameSection objectAtIndex:row]valueForKey:@"Title"];

If I try to type that in ViewDidLoad, it tells me : Use of undeclared identifier "indexPath" both for section and for row. I know it's because they only work inside index methods. But how can I adapt it for ViewDidLoad ? Some tutorials use a different copy method for that.. this is an example of one of them:

//---copy all the movie titles in the dictionary into the listOfMovies array---


listOfRecipes = [[NSMutableArray alloc] init];



for (NSString *year in array) //---get all the years---

{

//---get all the recipes for a particular category---

NSArray *movies = [movieTitles objectForKey:year];

for (NSString *title in movies)
{

[listOfRecipes addObject:title];

}

}


Here a photo of the plist, Thank you :)



RonC
Apr 1, 2011, 06:34 AM
NSUInteger section = [indexPath section];

NSUInteger row = [indexPath row];





NSString *key = [keys objectAtIndex:section];

NSArray *nameSection = [names objectForKey:key];

Something = [[nameSection objectAtIndex:row]valueForKey:@"Title"];

If I try to type that in ViewDidLoad, it tells me : Use of undeclared identifier "indexPath" both for section and for row. I know it's because they only work inside index methods. But how can I adapt it for ViewDidLoad ?

You can't.

Where do you expect indexPath to be set? When do you expect indexPath to be set? Perhaps you should check the View Programming Guide to see the View Lifecycle and understand what viewDidLoad means.

Nekbeth
Apr 1, 2011, 10:06 AM
I know you can't , but there are way to call it differently from using index, and that's what my question is about. ViewDidload method is everything you want to start after the view loaded. So, do you know another way to get those titles and not use index to find the rows? I'm very close to get them using other methods, such as "all keys" , "valueForKey", "Addobject", etc.