views:

157

answers:

4

i have a problem that i have spend about a week trying to solve it, but no luke up to now.

i have a uisearchbar implmented into my table view. and i also have two nsarray, one for tilte and one for discription. when i search through the array of the titles it returns the rights search, but when i click on a row that the search came with, i get "row 0" if i click on the first row. my question is how to make a connection between the two arrays so when the search rearrange the titles based on the user search the discription array correspond to the same row the title is at.

i appreciate any help.

A: 

Simply do not use two NSArrays, but just one with custom NSObject objects:

@interface SomeObject : NSObject {
    NSString *_title;
    NSString *_description;
}

- (BOOL)matchesKeywords:(NSString *)keywords;

@end

Then you have all your information stored in one class, the way Obj-C is meant to be. You can easily perform the search because the objects itself sort of knows whether it matches a given keyword, so when you'd like to change SomeObject you can easily manage those changes in the class itself.

JoostK
can you please show me how to use this method that you provided in the implementation class [ - (BOOL)matchesKeywords:(NSString *)keywords; ]my arrays are stored in a property list.i have tried so many ways and search all over the net, but can't figure it out.please help.
abuyousif
A: 

excuse me if I didn't get what you mean, if you can take a look at my source code and help me through it.

I want to display the title on one uitextView and the description on another uitextview on the same detailview.

but the search rearrange the rows and i end up with a diffrent title for a diff. description.

abuyousif
All I said is that you'll have to merge your title and detail arrays, so that you can have only one array with your data. Please try to implement this, based on your code I can see you're not completely new to Objective-C so with the basic understanding you have, try to achieve something. Do not ask right away, tell us what you tried and why it didn't work. Coding is a challenge, don't give up too fast ;)
JoostK
A: 

I did merge the two arrays into one, but that made the tableviewcell load alot slower because the cell is holding both, the title and description

abuyousif
That really can't be true. You're only assigning a *pointer* to an object to the cell, not the object itself. And please use StackOverflow how it's meant, using the question/answer/comments mechanism, then I'd be able to see when there is some activity here. Now, I won't get notified about new answers.
JoostK
i have managed to merge the two arrays into one in plist like thiskey type value_________________________________________________________root Array (2 items)item 0 dictionary (2 items) title String book1 description String this is a red bookitem 2 dictionary (2 items) title String book2 description String this is a white bookbut in the textDidChange: method, i could't make it work for(NSString *name in [sourceData valueForKey:@"title"]) {............ [[tableData valueForKey:@"title"] addObject:name]; please!!! help i really appreciate it
abuyousif
A: 

can you please show me the implementation code for the header code. how can i use this method - (BOOL)matchesKeywords:(NSString *)keywords; in the implementation code. i have tried so many ways, but none worked

@interface SomeObject : NSObject {

NSString *_title;
NSString *_description;

}

  • (BOOL)matchesKeywords:(NSString *)keywords;

@end

sam