I have simple relation function in my app, users can add other users to their contact list. Adding users to the relation works fine, the problem starts when i try to display the current users relations in a table view.
The problem is:
I launch the app from Xcode (i'm testing on iPhone device), (the root view controller is a blank view with a tab bar) then tap the button of the contact list on the tab bar, and nothing will be displayed. It's correct because there is no current user actually (i have an nslog in the viewDidLoad
that writes out the current users name). Therefore i log out and sign in with an existing username, but in this case the nslog doesn't works when i'm in the contact list, but it should, because now there is a current user. So i'm stopping the app in Xcode, run it again and it's working well. My opinion is the problem is with the tableViewTwo
's data reloading, it does not reloads normally, only when i stop and start running it again. I think it must be refreshed everytime when it's opened. Now i'm using the [tableViewTwo reloadData]
but it works only when i launch the app again. Do you have any ideas how can i refresh it properly? Or what should i do to solve this issue? (I don't wanna use the PFQueryTableViewController.)
My code:
- (void)viewDidLoad
{
[super viewDidLoad];
PFUser *current = [PFUser currentUser];
NSLog(@"current user is: %@",current);
self.simpleContact = [[PFUser currentUser] objectForKey:@"simpleContact"];
}
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
PFQuery *queryMyContacts = [self.simpleContact query];
[queryMyContacts orderByAscending:@"username"];
[queryMyContacts findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error %@ %@", error, [error userInfo]);
}
else {
self.allMyContact = objects;
[tableViewTwo reloadData];
}
}];
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.allMyContact count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FriendsCell *cell = [tableViewTwo dequeueReusableCellWithIdentifier:@"friendsDevCell"];
PFUser *user = [self.allMyContact objectAtIndex:indexPath.row];
cell.myContactUsernameLabel.text = user.username;
}