2014-12-29 1 views
-1

희망이 누구든지이 코드는 iOS 응용 프로그램의 Parse.com에서 작동하도록 할 수 있습니다.PFQuery 현재 사용자 특정 개체

5 개의 기본 열이있는 채널이라는 Parse.com 클래스에 쿼리하는 테이블이 있습니다.

  • 하나 "OBJECTID"
  • 2 :
  • 다섯 번째 "에 대해": "이름"
  • 넷째 : 포인터 < _USER (기본 클래스)>
  • 셋째는 "소유자" : "image"

    현재 사용자가 지정한 채널 "name", "about"및 "image"만 테이블에 쿼리해야합니다.

    내 코드에서 [query whereKey : @ "name"equalTo : [PFUser currentUser] .objectId] (현재 아래에 설명되어 있음)를 시도하면 queryForTable 메서드가 작동하지 않습니다. 모든 열의 현재 ACL은 Public Read입니다. 다음과 같이

내 현재 코드는 다음과 같습니다

- (id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [super initWithCoder:aDecoder]; 
    if (self) { 


     self.parseClassName = @"Channel"; 

     //self.textKey = @"name"; 

     self.pullToRefreshEnabled = YES; 

     self.paginationEnabled = YES; 

     self.objectsPerPage = 5; 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 


#pragma mark - UIViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 



} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    //self.canSearch = 0; 

} 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated]; 
} 



#pragma mark - Table view data source 

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {// 
//#warning Potentially incomplete method implementation. 
// Return the number of sections. 
// return 0; 
//} 

//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
//#warning Incomplete method implementation. 
// Return the number of rows in the section. 
//} 





#pragma mark - PFQueryTableViewController 



#pragma mark - Query 

- (PFQuery *)queryForTable 
{ 
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; 
    //[query whereKey:@"name" equalTo:[PFUser currentUser].objectId]; 
    query.cachePolicy = kPFCachePolicyCacheThenNetwork; 

    return query; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    MyChanTableViewCell *cell = (MyChanTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Configure the cell 
    PFFile *thumbnail = [object objectForKey:@"image"]; 
    PFImageView *thumbnailImageView = (PFImageView*)cell.showImage; 
    thumbnailImageView.image = [UIImage imageNamed:@"Image.jpg"]; 
    thumbnailImageView.file = thumbnail; 
    [thumbnailImageView loadInBackground]; 


    cell.mainTitle.text = [object objectForKey:@"name"]; 
    cell.detail.text = [object objectForKey:@"about"]; 


    return cell; 


} 


// Set CellForRowAtIndexPath 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *LoadMoreCellIdentifier = @"LoadMoreCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LoadMoreCellIdentifier]; 
    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LoadMoreCellIdentifier]; 
    } 
    return cell; 
} 

// Set TableView Height for Load Next Page 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if([self.objects count] == indexPath.row) { 
     // Load More Cell Height 
     return 60.0; 
    } else { 
     return 80.0; 
    } 
} 
+0

name 열에있는 값 중 하나라도 개체 ID와 같습니까? –

+0

아니요, name 열의 값은 string이고 Parse에 의해 할당 된 임의 값이있는 objectId 열이 있습니다 –

+0

안녕하세요 @LyndseyScott은 답장을 보내 주려고합니다. 아니요, name 열의 값은 string이며 Parse가 할당 한 임의의 값이있는 objectId 열이 있습니다. –

답변

1

당신은 출력하고자 내가 제대로 이해하면 owner는 현재 사용자입니다에 대한 name 값 :

[query whereKey:@"owner" equalTo:[PFUser currentUser]]; 

포인터와 비교할 때 전체 개체를 비교합니다. Parse SDK는 objectId 값과 객체 유형을 정확하게 비교하는 것으로 변환합니다. 걱정할 필요가 없습니다.

+0

Thnx @TimothyWalter 쿼리가 작동합니다! 이것은 백그라운드에서 일어나는 아주 미친 것입니다. 모든 Parse 문서에도 불구하고이 쿼리에는 PFRelational 유형이 있습니까?다른 모든 사용자의 목록을 쿼리하려면 관계형을 쿼리 할 필요가 없으며 사용자 클래스를 쿼리하면됩니까? Cheerzz –

0

귀하의 의견에서 분명히 보이는 것처럼, 을 (를)의 이름을 사용하여 실제로 쿼리하려하지 않습니다. objectID를 사용하여 객체 이름 을 검색하기 위해 쿼리하려고합니다.

현재 cellForRowAtIndexPath: 방법에서는 PFObject의 이름 속성에 이미 액세스하고 있습니다. 쿼리의 이름을 지정할 필요가 없습니다 (및 지정할 수 없음). 쿼리는 항상 PFObjects을 반환합니다. 당신은 단순히 objectID를 검색 할 수있는 적절한 열을 지정해야합니다 ... 그리고이 특정 컬럼은 "objectID에"(안 "이름") 예라고 :이 작동

- (PFQuery *)queryForTable 
{ 
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; 
    [query whereKey:@"objectID" equalTo:[PFUser currentUser].objectId]; 
    query.cachePolicy = kPFCachePolicyCacheThenNetwork; 

    return query; 
} 
+0

Thnx @LyndseyScott 귀하의 설명은 쿼리 작성과 테이블에서 PFObject에 액세스하는 방법을 이해하는 데 도움이되었습니다. 건배!!! –

+0

@LorencoGonzaga 당신이 좋은 해결책을 가지고있어 기쁘다. :) –

+0

그래! ;) 다른 사람들도 바래요! –

0
PFQuery *queryuser = [PFUser query]; 
    [queryuser whereKey:@"objectId" equalTo:[PFuser CurrentUser].objectId]; 
    [queryuser findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 

     NSString *name = [objects valueForKey:@"name"]; 
     NSLog(@"%@",name); 




    }]; 

희망 너를 위해서.

관련 문제