When do we need a BOOL variable pointer in Objective-C?

In this case, do we need a pointer to a BOOL variable in Objective-C?

I have code for a legible UITableView that has a function declaration:

- (void)toggle:(BOOL*)isExpanded section:(NSInteger)section; 

and its definition:

- (void)toggle:(BOOL*)isExpanded section:(NSInteger)section 
{
    *isExpanded = !*isExpanded; 
    NSArray *paths = [self indexPathsInSection:section];

    if (!*isExpanded)
    {
        [self.tableview deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
    }
    else 
    {
        [self.tableview insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
    }

* isExpanded =! * isExpanded; What is the point of this statement since I have never used this kind of operator in the case of a BOOL Variable.

Below are two other functions of the same code that are called in the sequence of the above function:

- (NSArray*)indexPathsInSection:(NSInteger)section 
{
    NSMutableArray *paths = [NSMutableArray array];
NSInteger row;
    for ( row = 0; row < [self numberOfRowsInSection:section]; row++ ) 
    {
        [paths addObject:[NSIndexPath indexPathForRow:row inSection:section]];
    }
    return [NSArray arrayWithArray:paths];
}

- (NSInteger)numberOfRowsInSection:(NSInteger)section 
{
    return [[sectionDataArray objectAtIndex:section] count];
}

sectionDataArray is an array for the number of rows in each section. I may be unclear, but if you got my question, explain it all.

Here is the link to this code

thank

+5
source share
5 answers

( ) , . BOOL , , , , . / , .

, . Cocoa, NSError , .. -(BOOL) doSomethingError:(NSError **)error.

+6

, BOOL. expanded BOOL s, , .

*isExpanded = !*isExpanded;

BOOL. , .

, , , deleteRowsAtIndexPaths:withRowAnimation: UITableView. - deleteSections:withRowAnimation: . insert...

, BOOL s. NSMutableArray .

, , expanded NO.

/* In the interface of the view controller */
NSMutableArray * expandedStatuses;

@property (nonatomic, retain) NSMutableArray * expandedStatuses;

/* In viewDidLoad or viewWillAppear:, as needed */
self.expandedStatuses = [NSMutableArray array];
for ( int i = 0; i < numberOfSections; i++ ) {
    [self.expandedStatuses addObject:[NSNumber numberWithBool:NO]];
}

, toggle:section: ,

/* Getting the expanded status of the section */
BOOL expanded = [[self.expandedStatuses objectAtIndex:section] boolValue];

/* Flipping the expanded status of the section */
[self.expandedStatuses replaceObjectAtIndex:section withObject:[NSNumber numberWithBool:!expanded]];

,

 [self.expandedStatuses removeObjectAtIndex:sectionIndexToDelete];

,

 /* Adding at the end */
 [self.expandedStatuses addObject:[NSNumber numberWithBool:NO]];

 /* Or adding it in between */
 [self.expandedStatuses insertObject:[NSNumber numberWithBool:NO] atIndex:sectionIndexToInsertAt];

NSMutableArray . .

+2

isExpanded toggle: .

*isExpanded = !*isExpanded;

BOOL , isExpanded - (iVar) pf class.

belwo

isExpanded = !isExpanded;
+1

*isExpanded = !*isExpanded;

isExpanded[0] = !isExpanded[0];
+1

BOOL

 typedef signed char     BOOL; 

BOOL.

-3

All Articles