0
I’m making an application to register students from a school using Tabbar, and one of the Tabs is the Query Tab.
In this tab, I have a search field, where the user must enter the student’s name and it will appear in a Textview, after clicking the search button.
I am using the Parse server, which provides me "Query" methods for the data, including already provides me an Array where objects are stored.
My search method, the search button action, is as follows:
- (IBAction)buscarAlunos:(id)sender {
// Busca
PFQuery *query = [PFQuery queryWithClassName:@"Aluno"];
// Busca com as Keys abaixo
[query selectKeys:@[@"firstName",@"lastName",@"telephone,classDate"]];
// Método fornecido pelo Parse
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// Método para efetuar a busca no Array objects com os dados do campo
[query whereKey:self.buscarTextField.text containsAllObjectsInArray:objects];
// Array para guardar os itens da busca
NSMutableArray* busca = [[NSMutableArray alloc]init];
[busca addObject:[NSString stringWithFormat:@"%@",[objects componentsJoinedByString:@"\n"]]];
// Exibir no textView
self.textViewResgate.text = [busca componentsJoinedByString:@"\n"];
}];
}
The problem is that mine textView
always displays the results with the keys and some codes. I believe I am not formatting properly.
The result appears like this:
<Aluno: FA49wkjYMA:(null)>{
firstName=Jose
lastName=da Silva
}
Could I get these keys and codes? I don’t know if stringWithFormat
is the best way to display.
Ok, my answer ta means "thigh" because I forgot that this is a repetition block, so you can use a Nsmutablestring to give the "append" of the names before assigning them to your text field. If you need a hand with that, just ask ;)
– Jan Cássio
Nice of you to help. In the case of the mutable string, you can instantiate a variable of type Nsmutablestring and use the instance method "appendFormat" in the repetition block to scan all items within "Objects". Then just assign it to the text in your text view.
– Jan Cássio
One thing that is happening now, is that whenever I click the search field it returns me the last registered, and never what I typed in the field. Would it have something to do with Dispatch, or the loop? I will try to make the appendFormat.
– Joao Paulo
It makes sense, because in the snippet I sent you, it will always keep the last name and surname of the last record (my fault), when you do with
appendFormat
, you will have a string with all names and surnames merged.– Jan Cássio
hmm cool. I tried to make the appendFormat, but I’m really not getting it. I tried something like this: Nsmutablestring* searchAlunos = [[Nsmutablestring alloc] init]; and then self.textViewResgate.text = [searchAlunos appendFormat:@"firstName"]; I think the typing syntax is confusing me. Does the topic let you edit your answer up there in the code? I think I’ll get a better view. Thanks again Jan.
– Joao Paulo
I think I got it. What happened was this, Parse’s method that I was using wasn’t doing the Query the right way. I picked one of the Keys to type in the search field, sounding the same as the typed one. So: [query whereKey:@"firstName" equalTo:self.searchTextField.text];Then I did what you said inside findobjectsinBackgroundWithBlock and Dispatch. Nsmutablestring* searchSilver = [[Nsmutablestring alloc] init]; and self.textViewResgate.text = [searchSilver stringByAppendingFormat:@"First name: %@",Object[@"firstName"],Object[@"lastname"]];
– Joao Paulo
Thank you very much Jan. Needing too, just talk.
– Joao Paulo