2015-11-20 64 views
1

分析查詢檢索下一個對象,我想從我的解析類檢索下一組解析數據,但我的立場仍與我怎麼可能做到什麼,我試圖做我完全。中的NSNumber堆棧

實施例用戶與尖端#1啓動,並隨後按下下一個和呈現尖#2,等等等等。

我有我的「下一步」按鈕解析查詢應解析中加載下一個尖端插入我的UILabel稱爲tipBody和下一個順序根尖數到我tipNumber標籤。

enter image description here

- (IBAction)nextTipAction:(id)sender 
{ 
    [ProgressHUD show:@"Loading Next Tip"]; 
    //Get Current Comments// 

    __weak typeof (self) weakSelf = self; 

    PFQuery *query = [PFQuery queryWithClassName:@"Archive"]; 
    [query whereKey:@"body" equalTo:@"tipNumber"]; 
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (!error) 
     { 

      weakSelf.tipNumberLabel.text =[NSString stringWithFormat:@"Tip Number: %ld", [[weakSelf.currentTip objectForKey:@"tipNumber"] integerValue]]; 
      [self.currentTip incrementKey:@"tipNumber" byAmount:@+1]; 
      [ProgressHUD dismiss]; 

     } 
     else 
     { 
      [ProgressHUD dismiss]; 
      [ProgressHUD showError:@"Sorry! Unable to load Tips"]; 
      // Log details of the failure 
      NSLog(@"Error: %@ %@", error, [error userInfo]); 
     } 
    }]; 
} 

任何幫助將非常感謝!謝謝!

回答

1

檢查你的代碼如下。

- (IBAction)nextTipAction:(id)sender 
{ 
    NextTipNumber++; // Assume that on didload it initiate to 1 and also load on view didload you have load first tip. 

    [ProgressHUD show:@"Loading Next Tip"]; 
    //Get Current Comments// 

    __weak typeof (self) weakSelf = self; 

    PFQuery *query = [PFQuery queryWithClassName:@"Archive"]; 
    [query orderByAscending:@"tipNumber"]; 
    [query setLimit: NextTipNumber]; // Set the limit according which tip you want to access 
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
     if (!error) 
     { 
      PFObject *ArchiveObject = [objects lastObject]; 
      weakSelf.tipNumberLabel.text = [ArchiveObject objectForKey:@"tipNumber"]; 
      weakSelf.tipBody.text = [ArchiveObject objectForKey:@"body"]; 

      [ProgressHUD dismiss]; 
     } 
     else 
     { 
      [ProgressHUD dismiss]; 
      [ProgressHUD showError:@"Sorry! Unable to load Tips"]; 
      // Log details of the failure 
      NSLog(@"Error: %@ %@", error, [error userInfo]); 
     } 
    }]; 
} 
+0

這是在只有兩個標籤(tipNumberLabel和tipBody)和一個按鈕(nextButton)的視圖控制器中。當我實現你的代碼時,它不會加載與tipBody相關的下一個tipNumber。 –

+1

檢查我編輯的答案@JoshuaHart,你有沒有? – Jaimish

+0

是NextTipNumber ++的一個整數,我應該在我的頭文件中聲明? –