2015-05-28 4 views
0

Я попытался следующий код до сих пор:Как я могу показать массив PFUser из Parse в UITableVIew в iOS?

PFGeoPoint * myGeoPoint = [PFUser currentUser][@"coordinates"]; // Your geoPoint 
PFQuery *query = [PFUser query]; 
[query includeKey:@"User"]; 
[query whereKey:@"coordinates" nearGeoPoint:myGeoPoint withinMiles:radiusInMiles]; 
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
    if(!error){ 
for (PFUser *object in objects){ 
      users = (NSArray*)[object ObjectForKey:@"User"]; 
     } 
     [self.tableView reloadData]; 
    } 

}  

}]; 
- (PFUser*) objectAtIndexPath:(NSIndexPath*)indexPath { 
PFUser *object = [PFUser objectWithClassName: @"User"]; 
[object setObject:[users objectAtIndex:indexPath.row] forKey:@"User"]; 
return object; 
} 
// Use myObjects for numberOfRowsInSection: 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section { 
return users.count; 
} 
//Use your custom object for cellForRowAtIndexPath: 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath object:(PFUser *)object { 
static NSString *simpleTableIdentifier = @"cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
} 

// Configure the cell using object 
UILabel *reviewLabel = (UILabel *)[cell viewWithTag:10]; 
reviewLabel.text = [object objectForKey:object.username]; 
PFFile *userImageFile = object[@"profilePic"]; 
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) { 
    if (!error) { 
     if (imageData != nil) 
      cell.imageView.image = [UIImage imageWithData:imageData]; 
     else cell.imageView.image= [UIImage imageNamed:@"defaultPerson"]; 
    } 
}]; 

} 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

    SMChatViewController *chatController = [SMChatViewController alloc]; 

// [chatController initWithPhoto:image]; 

    [self presentModalViewController:chatController animated:YES]; 

} 

В этом коде я извлечения массива PFUsers как «объекты» .Когда я храню массив объектов для пользователей, которые он возвращает в качестве пустой. Так может ли кто-нибудь предложить мне что-то, что я могу установить имя пользователя и profilepic в tableView?

Log output of objects

+0

вы можете войти и проверить, что вы получите правильный массив '' objects' в findObjectsInBackgroundWithBlock' –

+0

@VivekMolkar да я могу получить массив в «объектов», но не может загрузить его в «пользователи». – Sushrita

+0

Можете ли вы показать мне значения в 'objects' –

ответ

0
- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath*)indexPath { 

static NSString *simpleTableIdentifier = @"cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
} 

    PFUser *user = (PFUser*)[users objectAtIndex:indexPath.row]; 

cell.textLabel.text=user.username; 

PFFile *userImageFile = user[@"profilePic"]; 
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) { 
    if (!error) { 
if (imageData != nil) 
      cell.imageView.image = [UIImage imageWithData:imageData]; 
     else cell.imageView.image= [UIImage imageNamed:@"defaultPerson.png"]; 
    } 
}]; 
return cell; 
} 
0

Я думаю, вопрос не является правильным. Попробуйте это:

PFGeoPoint * myGeoPoint = [PFUser currentUser][@"coordinates"]; // Your geoPoint 
PFQuery *query = [PFQuery queryWithObject:@"_User"]; 
NSArray *userList = [NSArray new]; 

[query whereKey:@"coordinates" nearGeoPoint:myGeoPoint withinMiles:radiusInMiles]; 
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
    if(!error){ 
     userList = objects; 
     [self.tableView reloadData]; 
    } 

}]; 

В своем коде вы просите объекты «Пользователь», то выборка поле «User» от этого объекта.

+0

запрос правильный, но я не могу загрузить массив в tableView, вы можете помочь? – Sushrita

+0

вы можете помочь предложить что-то, что я могу загрузить массив в tableView? – Sushrita