C.Johns
C.Johns

Reputation: 10245

how to use a bool variable in objective c

I am currently trying to use a boolean to check for when an event happens.. However I'm not sure how to use a boolean value in objective c

Heres what I'm doing.

//.h

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

//.m

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

So I'm checking if the filtered array has no values if thats the case then I want to stop my UIActivityIndicator thats Is currently running in my uitableview cell.

- (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
        }
    }

//...

My problem happens in the if parameters..

(self.removeActivityIndicator == 0)

I have no idea how to check if the BOOL is true or not.

any help would be greatly appreciated.

Upvotes: 3

Views: 10117

Answers (2)

Jesse Naugher
Jesse Naugher

Reputation: 9820

there are a number of ways. just using the name with the NOT operator (!) in front works: !self.removeActivityIndicator or self.removeActivityIndicator == NO or self.removeActivityIndicator == FALSE will all work

Also as an aside: A BOOL type is a primitive, and therefore does not need to be declared as a pointer (using an *) as you have done. BOOL remoteActivityIndicator; is what you want as the declaration.

Upvotes: 3

SentineL
SentineL

Reputation: 4732

in objective c true and false are YES and NO. Or, you can use this code:

if (!self.removeActivityIndicator) {}; 

it means

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

offcorse, removeActivityIndicator must be BOOL type

Upvotes: 5

Related Questions