Inserting and Deleting Cells and Rows
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic provides a conceptual overview of inserting and deleting cells and rows from the IGGridView™ control with code examples for each.

Required background

The following table lists the topics required as a prerequisite to understanding this topic.

Topic

Purpose

Adding the Grid Framework File

This topic explains the requirements for adding the grid framework file to an Xcode project; a requirement for using the IGGridView control.


In this topic


Introduction

Inserting and deleting summary

The IGGridView’s methods for inserting and deleting cells and rows are very similar to the generic UITableView control. Once the underlying data has been updated, use one of the following methods to inform the IGGridView of the updates.

  • -(void)insertCellsAtPaths:(NSArray *)path withAnimation:(IGGridViewAnimation)animation
  • -(void)insertRowsAtPaths:(NSArray *)paths withAnimation:(IGGridViewAnimation)animation
  • -(void)deleteCellsAtPaths:(NSArray *)paths withAnimation:(IGGridViewAnimation)animation
  • -(void)deleteRowsAtPaths:(NSArray *)paths withAnimation:(IGGridViewAnimation)animation

When rows or cells are inserted or deleted, the IGGridView uses the supplied IGGridViewAnimation to create a visual transition with the change of data. It is not necessary to call the reloadData or updateData methods on the IGGridView, they will be called automatically. The following bullets are the enumeration values for IGGridViewAnimation.

  • IGGridViewAnimationAutomatic
  • IGGridViewAnimationBottom
  • IGGridViewAnimationFade
  • IGGridViewAnimationLeft
  • IGGridViewAnimationNone
  • IGGridViewAnimationRight
  • IGGridViewAnimationTop
Note: The IGGridViewAnimationAutomatic method uses the IGGridViewAnimationTop for row animation and the IGGridViewAnimationLeft for cell animation.

Inserting Cells and Rows – Code Example

Description

To insert a new cell or row to the IGGridView simply add the new cell or row to the data source, invalidate the data, and finally instructing the IGGridView to insert the new cell or row with the specified animation.

Inserting Cells - Code

In Objective-C:

-(void)insertTouched:(id)sender
{
    IGGridViewDataSourceHelper* ds = _gridView.dataSource;
    NSString* item = @”New Item”;
    IGCellPath* path1 = [IGCellPath pathForRow:1 inSection:0 inColumn:0];
    NSMutableArray* data = (NSMutableArray*)ds.data;
    [data insertObject:item atIndex:1];
    [ds invalidateData];
    [_gridView insertCellsAtPaths:[NSArray arrayWithObjects:path1, nil] withAnimation:IGGridViewAnimationLeft];
}

In C#:

   IGGridViewDataSourceHelper ds = (IGGridViewDataSourceHelper)gridView.DataSource;
   IGCellPath path = new IGCellPath(1, 0, 0);
   ArrayList data = new ArrayList(ds.Data);
   data.Add("New value");
   ds.Data = (NSObject[])data.ToArray();
   gridView.InsertCells(new NSObject[]{path}, IGGridViewAnimation.IGGridViewAnimationLeft);

Inserting Rows – Code

In Objective-C:

-(void)insertTouched:(id)sender
{
    IGGridViewDataSourceHelper* ds = _gridView.dataSource;
    NSString* item = @”New Item”;
    IGRowPath* path1 = [IGRowPath pathForRow:1 inSection:0];
    NSMutableArray* data = (NSMutableArray*)ds.data;
    [data insertObject:item atIndex:1];
    [ds invalidateData];  
    [_gridView insertRowsAtPaths:[NSArray arrayWithObjects:path1, nil] withAnimation:IGGridViewAnimationTop];
}

In C#:

   IGGridViewDataSourceHelper ds = (IGGridViewDataSourceHelper)gridView.DataSource;
   IGRowPathpath = new IGRowPath(1, 0);
   ArrayList data = new ArrayList(ds.Data);
   data.Add("New value");
   ds.Data = (NSObject[])data.ToArray();
   gridView.InsertRows(new NSObject[]{path}, IGGridViewAnimation.IGGridViewAnimationTop);

Deleting Cells and Rows – Code Example

Description

To delete a cell or row from the IGGridView simply remove the cell or row from the data source, invalidate the data, and finally instructing the IGGridView to update the visually displayed data with the specified animation.

Deleting Cells - Code

In Objective-C:

-(void)deleteClicked:(id)sender
{
    IGGridViewDataSourceHelper* ds = _gridView.dataSource;
    IGCellPath* path = [IGCellPath pathForRow:0 inSection:0 inColumn:0];
    NSMutableArray* data = (NSMutableArray*)ds.data;
    [data removeObjectAtIndex:0];
    [ds invalidateData];       
    [_gridView deleteCellsAtPaths:[NSArray arrayWithObjects:path , nil]withAnimation:IGGridViewAnimationLeft];
}

In C#:

  IGGridViewDataSourceHelper ds = (IGGridViewDataSourceHelper)gridView.DataSource;
   IGCellPath path = new IGCellPath(0, 0, 0);
   ArrayList data = new ArrayList(ds.Data);
   data.RemoveAt(0);
   ds.Data = (NSObject[])data.ToArray();
   gridView.DeleteCells(new NSObject[]{path}, IGGridViewAnimation.IGGridViewAnimationLeft);

Deleting Rows - Code

In Objective-C:

-(void)deleteClicked:(id)sender
{
    IGGridViewDataSourceHelper* ds = _gridView.dataSource;
    IGRowPath* path = [IGRowPathpathForRow:0 inSection:0];
    NSMutableArray* data = (NSMutableArray*)ds.data;
    [data removeObjectAtIndex:0];
    [ds invalidateData];       
    [_gridView deleteRowsAtPaths:[NSArray arrayWithObjects:path , nil]withAnimation:IGGridViewAnimationTop];
}

In C#:

  IGGridViewDataSourceHelper ds = (IGGridViewDataSourceHelper)gridView.DataSource;
   IGRowPath = new IGRowPath (0, 0);
   ArrayList data = new ArrayList(ds.Data);
   data.RemoveAt(0);
   ds.Data = (NSObject[])data.ToArray();
   gridView.DeleteRows(new NSObject[]{path}, IGGridViewAnimation.IGGridViewAnimationTop);

Related Content

Topics

The following topics provide additional information related to this topic.

Topic

Purpose

This topic provides basic information about creating an instance of the IGGridView and displaying data to help you with getting up and running with using the control.

This section serves as an introduction to the IGGridView’s key features and functionalities.