0

Im currently using following code to display an array inside of an UItextView / label / textfield :

  PFQuery *query = [PFQuery queryWithClassName:@"appMsg"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // The find succeeded.
            NSLog(@"Successfully retrieved %d scores.", objects.count);
            // Do something with the found objects
            for (PFObject *object in objects) {
                NSString *besked = object[@"besked"];
                msgRecieved0.text = besked;
                NSLog(@"Object values %@",[objects valueForKey:@"besked"]);

            }
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];

i have tried to set the NSString to :

NSArray *besked = object[@"besked"];
                msgRecieved0.text = besked[0];
                msgRecieved1.text = besked[1];
                msgRecieved2.text = besked[2];

But again i get an error.

i have tried all i know, and i don't know what i should do to display a "list" of the arrays. I would like to show the first 10 values coming from the array

5
  • What error(s) are you getting? Commented Aug 26, 2014 at 16:17
  • -[__NSCFString objectAtIndexedSubscript:]: unrecognized selector sent to instance Commented Aug 26, 2014 at 16:19
  • Have you put breakpoints in? Is besked storing the correct string? Commented Aug 26, 2014 at 16:24
  • There should be n breakpoints. beaked is stored as a string. Commented Aug 26, 2014 at 16:28
  • When just running: NSLog(@"Object values %@",[objects valueForKey:@"besked"]); I'm able to get all the values. Commented Aug 26, 2014 at 16:28

1 Answer 1

1

PFObject will not respond to Dictionary style element addressing. You must use keyValue coding style code.

Instead of NSString *besked = object[@"besked"];, try this:

NSString *besked = [object objectForKey:@"besked"];

Edit - This might be what you need, if the Parse object is an array.

NSArray* besked = [object objectForKey:@"besked"];
NSString*  str0 = [besked objectAtIndex:0];
NSString*  str1 = [besked objectAtIndex:1];
NSString*  str2 = [besked objectAtIndex:2];
Sign up to request clarification or add additional context in comments.

20 Comments

expected method to read array element not found on object op type "NSString *"
What does "besked" store in your Parse database?
random messages like : how are you?, leaving for football, see you later ;), etc.
Then you cannot do: NSArray *besked = object[@"besked"]; it must be what I wrote.
but how do i then get more then the latest string?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.