Skip to content

Adding Columns

cmancushman edited this page Oct 28, 2017 · 9 revisions

How to Add Columns

In order to properly add a column, you must first instantiate an instance of StackBaseColumn using one of its specialized constructors and then add that instance to the table using the table's addColumns: method.


Instantiate Text Column

Declaration

+(instancetype)textColumnWithName:(NSString *)name

Example

[StackBaseColumn textColumnWithName:@"Name"];

Instantiate Numeric Column

Declaration

+(instancetype)numericColumnWithName:(NSString *)name shouldBeUnsigned:(BOOL)isUnsigned;

Example

[StackBaseColumn numericColumnWithName:@"Number" shouldBeUnsigned:NO];

Instantiate Date-Time Column

Declaration

+(instancetype)dateTimeColumnWithName:(NSString *)name type:(StackBaseDateTimeType *)type;

Example

[StackBaseColumn dateTimeColumnWithName:@"Date" type:StackBaseDateTimeTypeDATE];

Note on Date-Time Columns
Date-Time columns are unique in that they accept a StackBaseDateTimeType parameter. This parameter affects the formatting of data the column accepts. There are five different types, and they affect data formatting as follows:

StackBaseDateTimeTypeDATE accepts data in the format: 'YYYY-MM-DD'

StackBaseDateTimeTypeTIME accepts data in the format: 'HH:MM:SS'

StackBaseDateTimeTypeYEAR accepts data in the format: 'YYYY'

StackBaseDateTimeTypeDATETIME accepts data in the format: 'YYYY-MM-DD HH:MM:SS'

StackBaseDateTimeTypeTIMESTAMP does not accept data. Will automatically assign a value based on the exact time data is posted in the format: 'YYYY-MM-DD HH:MM:SS'

It is important to understand that a date-time column will try to parse a formatted value out of whatever input it receives, even if that input does not follow the format it was assigned. However, a date-time column will always return data in the format it was assigned.


Add a Column to an Existing Table

Declaration

-(void)addColumns:(NSArray<StackBaseColumn *> *)columns completionBlock:(StackBaseEditCompletion) compBlock;

Example

[weakSelf.table addColumns:@[[StackBaseColumn textColumnWithName:@"Name"]] completionBlock:^(BOOL success, NSString *responseMessage) {
    
    if(success){
        
        NSLog(@"Operation Successful.");
        
    }else{
        
        NSLog(@"Operation Unsuccessful.");
        
    }
    
}];

Note
Columns can also be included when creating a new table. See 'Adding Tables.'

Clone this wiki locally