2011-11-30 85 views
3

目前,我試圖用一個布爾值來檢查時,事件發生.. 但是我不知道如何在目標C使用一個布爾值如何使用布爾變量的目標C

繼承人我在做什麼。

//.h

BOOL *removeActivityIndicator; 
//.. 
@property (nonatomic, assign) BOOL *removeActivityIndicator; 

//.m

if ([filteredArray count] == 0) 
     { 
      self.removeActivityIndicator = YES; 
     } 
     else if([filteredArray count] !=0) 
     { 
      tempArray = filteredArray; 
     } 
} 

所以我檢查,如果過濾的數組沒有值如果多數民衆贊成的話,那麼我想阻止我UIActivityIndi​​cator這就是目前正在我的uitableview單元格中運行。

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

//Stop ActivityIndicator if arrays have no values for the user 
    if(indexPath.section == 0) 
    {   
     if ((indexPath.row == 1) && (self.removeActivityIndicator == 0)) //problem 
     { 
      //Stop activity indicators 
      //[activityView stopAnimating]; 
      cell.accessoryView = nil;//replaces activity indicator 
     } 
    } 

//... 

我的問題發生在如果參數..

(self.removeActivityIndicator == 0) 

我不知道如何檢查,如果BOOL是真還是假。

任何幫助將不勝感激。

+1

嘗試使用self.removeActivityIndi​​cator == NO; – user170317

回答

4

in objective c true and false are YES and NO。或者,您可以使用此代碼:

if (!self.removeActivityIndicator) {}; 

這意味着

if (self.removeActivityIndicator == NO) {}; 

offcorse,removeActivityIndicator必須BOOL

+0

謝謝..這工作,但它仍然沒有解決我的問題。 由於某種原因,當我允許這種情況發生時,它根本不顯示我的活動指標..真的開始糾纏我了。 –

+0

活動指標appiares在一段時間。如果你刪除它太快,它不會appiar。如果不是,在添加它的地方發佈一些代碼。更好地爲此做出另一個解決方案:其他人會看到它的更多詭計。 – SentineL

+0

現在讓它正常工作:)當我將協議調用到我正在處理的新主視圖中時,只需將其設置爲YES即可。它工作薄荷!歡呼的幫助! –

3

有多種方式。只是使用的名稱與NOT運算符在前面的作品(!):!self.removeActivityIndicatorself.removeActivityIndicator == NOself.removeActivityIndicator == FALSE將所有的工作

同樣作爲旁白:BOOL類型是一種原始的,因此並不需要被聲明爲指針(使用*)就像你所做的那樣。 BOOL remoteActivityIndicator;是你想要的聲明。