Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
TableView not showing parsed data from MutableArray
I have a UITableView in which data is being parsed from a server. I extract the data parsed into an NSString, which I then turn into an NSArray (a list of names). I know this is working from using an NSLog.
Now here is where I am stuck. I have then being turning that NSArray into an NSMutableArray for the TableView to load the rows with. But no rows are appearing, the cells are not being filled with data. I don't know if my code is wrong, i'm a new developer, and am not experienced enough to trouble shoot this myself. I'm not getting any errors, just no rows. Please help, it is for my graduate project.
Here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
[self retrieveData];
//these are various lines of code I have tried to make the rows load the Array
} This retrieves the data for LocationArray, that i'm trying to fill the tableview with:
-(void)retrieveData {
PFUser *currentUser = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@"Labels"]; [query whereKey:@"User" equalTo:currentUser]; [query findObjectsInBackgroundWithBlock:^(NSArray *labels, NSError *error) { if (!labels) { NSLog(@"The getFirstObject request failed."); } else { labels = [query findObjects]; NSLog(@"retrieved related label: %@", labels); // this retrieves the data
self.result = [[labels valueForKey:@"locationLabels"] componentsJoinedByString:@", "]; NSLog(@"retrieved related label: %@", self.result); // this turns data into string // I think below is wrong maybe? self.labelArray = [self.result componentsSeparatedByString:@", "]; NSLog(@"retrieved related label: %@", self.labelArray); // this turns data into array
} }]; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section.
I have a UITableView in which data is being parsed from a server. I extract the data parsed into an NSString, which I then turn into an NSArray (a list of names). I know this is working from using an NSLog.
Now here is where I am stuck. I have then being turning that NSArray into an NSMutableArray for the TableView to load the rows with. But no rows are appearing, the cells are not being filled with data. I don't know if my code is wrong, i'm a new developer, and am not experienced enough to trouble shoot this myself. I'm not getting any errors, just no rows. Please help, it is for my graduate project.
Here is my code:
--snip--
}
Please use code tags for your code. Just pasting code into your post makes it really difficult to read.
Also, you should indicate when you're using third party libraries, and mention the libraries in your subject line. That way, people who are familiar with the library you're using will see your post and respond.
I saw a class PFQuery, Which looks to be part of a "Parse iOS SDK", which seems to be some library for parsing data from FaceBook?
In any case, I was able to find some documentation on the PFQuery class you're using. The method findObjectsInBackgroundWithBlock that you're using does it's search in the background. It moves on to the next statement in your code immediately, before the search is complete.
The code you put in the block gets executed once the search is complete. You need to restructure your code so the stuff that happens after the search is complete is in the code block.
Something like this:
- (void)viewDidLoad
{ [super viewDidLoad]; [self retrieveData]; //This next line will execute before the find is complete. //Do not try to handle search results here. It won't work. } This retrieves the data for LocationArray, that i'm trying to fill the tableview with:
-(void)retrieveData {
PFUser *currentUser = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@\"Labels\"]; [query whereKey:@\"User\" equalTo:currentUser]; [query findObjectsInBackgroundWithBlock:^(NSArray *labels, NSError *error) { //This code gets called after the find completes if (!labels) { NSLog(@\"The getFirstObject request failed.\"); } else { labels = [query findObjects]; NSLog(@\"retrieved related label: %@\", labels); // this retrieves the data
//[B]Put your results into whatever array you need here[/B]. //I'm not sure what array your tableview uses... self.locationArray = [labels valueForKey:@\"locationLabels\"]; [self.tableView reloadData];
NSLog(@\"retrieved related label: %@\", self.locationArray); } }]; }
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
i'm a new developer, and am not experienced enough to trouble shoot this myself. I'm not getting any errors, just no rows. Please help, it is for my graduate project.
--snip--
}
This is for a graduate project? In what subject? It scares me that this is for a graduate project, but you don't have any idea what you are doing.
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
This is for a graduate project? In what subject? It scares me that this is for a graduate project, but you don't have any idea what you are doing.
Hi, thanks so much for helping, its all working now. Sorry i'm new objective-C and forums, I know for next time :)
Its for Interactive Media Production, we never actually learnt how to code apps on my course, i just wanted to do something different for my graduate project, and try to learn it all myself, hence not having a clue! But thats why i'm thankful for these forums, its a lot easier to make sense of stuff on here instead of reading out of books.
Replies
Also, you should indicate when you're using third party libraries, and mention the libraries in your subject line. That way, people who are familiar with the library you're using will see your post and respond.
I saw a class PFQuery, Which looks to be part of a "Parse iOS SDK", which seems to be some library for parsing data from FaceBook?
In any case, I was able to find some documentation on the PFQuery class you're using. The method findObjectsInBackgroundWithBlock that you're using does it's search in the background. It moves on to the next statement in your code immediately, before the search is complete.
The code you put in the block gets executed once the search is complete. You need to restructure your code so the stuff that happens after the search is complete is in the code block.
Something like this:
- (void)viewDidLoad
{
[super viewDidLoad];
[self retrieveData];
//This next line will execute before the find is complete.
//Do not try to handle search results here. It won't work.
}
This retrieves the data for LocationArray, that i'm trying to fill the tableview with:
-(void)retrieveData
{
PFUser *currentUser = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@\"Labels\"];
[query whereKey:@\"User\" equalTo:currentUser];
[query findObjectsInBackgroundWithBlock:^(NSArray *labels, NSError *error) {
//This code gets called after the find completes
if (!labels) {
NSLog(@\"The getFirstObject request failed.\");
} else {
labels = [query findObjects];
NSLog(@\"retrieved related label: %@\", labels); // this retrieves the data
//[B]Put your results into whatever array you need here[/B].
//I'm not sure what array your tableview uses...
self.locationArray = [labels valueForKey:@\"locationLabels\"];
[self.tableView reloadData];
NSLog(@\"retrieved related label: %@\", self.locationArray);
}
}];
}
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThis is for a graduate project? In what subject? It scares me that this is for a graduate project, but you don't have any idea what you are doing.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIts for Interactive Media Production, we never actually learnt how to code apps on my course, i just wanted to do something different for my graduate project, and try to learn it all myself, hence not having a clue! But thats why i'm thankful for these forums, its a lot easier to make sense of stuff on here instead of reading out of books.
Thanks for the help
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome