Saturday, June 8, 2013

UITableView tableView indentationLevelForRowAtIndexPath example in Objective C (iOS).


UITableView tableView indentationLevelForRowAtIndexPath

Asks the delegate to return the level of indentation for a row in a given section.

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

Parameters of [UITableView tableView indentationLevelForRowAtIndexPath]
tableView
The table-view object requesting this information.
indexPath
An index path locating the row in tableView.

Return Value of [UITableView tableView indentationLevelForRowAtIndexPath]
Returns the depth of the specified row to show its hierarchical position in the section.

UITableView tableView indentationLevelForRowAtIndexPath example.
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{

            NSInteger theLevel=0;
            if ( indexPath.row==1) {
                theLevel=5;
            }
            return theLevel;
        }

Example of [UITableView tableView indentationLevelForRowAtIndexPath].
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
  if(tableView.editing == YES){
    return 1; // or higher integer
  } else {
    return 0;
  }
}

UITableView tableView indentationLevelForRowAtIndexPath example.
- (NSInteger)tableView:(UITableView *)tableView
indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [indexPath row] % 2;
}

End of UITableView tableView indentationLevelForRowAtIndexPath example article.