//
//  Print2DBarcodeViewController.m
//  SIIMpaPrinterSample
//

#import "Print2DBarcodeViewController.h"
#import "PrinterManager.h"
#import "ValueManager.h"
#import "ValueViewController.h"

@interface Print2DBarcodeViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation Print2DBarcodeViewController {
    UIView *_indicatorView;
    ValueViewController *_viewController;
    NSInteger _sectionIndex;
    int _footerSize;
    NSInteger _frameWidth;
    NSArray *_sectionTable;
}

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_TYPE_TABLE = 7;
static NSString *const TWO_DIMENSION_BARCODE_TYPE_TABLE[] = {
    TWO_DIMENSION_BARCODE_TYPE_QR_CODE,
    TWO_DIMENSION_BARCODE_TYPE_PDF417,
    TWO_DIMENSION_BARCODE_DATA_MATRIX,
    TWO_DIMENSION_BARCODE_MAXI_CODE,
    TWO_DIMENSION_BARCODE_GS1_STACKED,
    TWO_DIMENSION_BARCODE_GS1_OMNI_DIRECTIONAL,
    TWO_DIMENSION_BARCODE_GS1_EXPANDED_STACKED
};

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_QR_CODE_MODEL_TABLE = 2;
static NSString *const TWO_DIMENSION_BARCODE_QR_CODE_MODEL_TABLE[] = {
    TWO_DIMENSION_BARCODE_QR_CODE_MODEL_1,
    TWO_DIMENSION_BARCODE_QR_CODE_MODEL_2
};

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_MODE_TABLE = 2;
static NSString *const TWO_DIMENSION_BARCODE_PDF417_MODE_TABLE[] = {
    TWO_DIMENSION_BARCODE_PDF417_MODE_STANDARD,
    TWO_DIMENSION_BARCODE_PDF417_MODE_COMPACT
};

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_TABLE = 31;
static NSString *const TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_TABLE[] = {
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_AUTO,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_10x10,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_12x12,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_14x14,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_16x16,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_18x18,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_20x20,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_22x22,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_24x24,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_26x26,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_32x32,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_36x36,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_40x40,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_44x44,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_48x48,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_52x52,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_64x64,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_72x72,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_80x80,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_88x88,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_96x96,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_104x104,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_120x120,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_132x132,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_144x144,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_8x18,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_8x32,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_12x26,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_12x36,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_16x36,
    TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_16x48
};

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_TABLE = 4;
static NSString *const TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_TABLE[] = {
    TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_2,
    TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_3,
    TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_4,
    TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_5
};

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE = 16;
static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_MODULE_SIZE_TABLE = 8;
static NSString *const TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE[] = {
    TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_2,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_3,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_4,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_5,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_6,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_7,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_8,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_9,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_10,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_11,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_12,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_13,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_14,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_15,
    TWO_DIMENSION_BARCODE_MODULE_SIZE_16
};

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_TABLE = 4;
static NSString *const TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_TABLE[] = {
    TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_L,
    TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_M,
    TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_Q,
    TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_H
};

static NSUInteger const SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_TABLE = 9;
static NSString *const TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_TABLE[] = {
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_0,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_1,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_2,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_3,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_4,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_5,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_6,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_7,
    TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_8
};

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _sectionIndex = -1;
    self.tableView.delegate = (id <UITableViewDelegate>)self;
    self.tableView.dataSource = (id <UITableViewDataSource>)self;
    [self initIndicatorView];
    [self setDefaultValue];
    [self initSectionTable];
}

-(void)viewDidDisappear:(BOOL)animated {
    [self removeKeyboardNotification];
    [super viewDidDisappear:animated];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self addKeyboardNotification];
    [self reloadTableView];
    [self reloadViewSize];
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    //
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        [self reloadViewSize];
    } completion:nil];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _sectionTable.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section < _sectionTable.count) {
        return _sectionTable[section];
    } else {
        return @"";
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    cell.textLabel.text = @"";
    cell.textLabel.numberOfLines = 0;
    if (indexPath.section < _sectionTable.count) {
        NSString *sectionTitle = _sectionTable[indexPath.section];
        if (([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_DATA_SECTION])
            || ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_HEIGHT_SECTION])
            || ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_COLUMN_SECTION])
            || ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ROW_SECTION])) {
            UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, _frameWidth - 20, cell.frame.size.height)];
            textField.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;
            textField.returnKeyType = UIReturnKeyDone;
            textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
            textField.tag = indexPath.section;
            textField.clearButtonMode = YES;
            [textField setDelegate:self];
            if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_DATA_SECTION]) {
                textField.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA];
            } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_HEIGHT_SECTION]) {
                textField.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT];
            } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_COLUMN_SECTION]) {
                textField.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN];
            } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ROW_SECTION]) {
                textField.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW];
            }
            [cell.contentView addSubview:textField];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryNone;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_TYPE_SECTION]) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODE_SECTION]) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE];
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION]) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE];
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ERROR_CORRECT_SECTION]) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT];
        }
    }
    return cell;
}

#pragma mark - TextField
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    if (0 <= textField.tag && textField.tag < _sectionTable.count) {
        NSString *sectionTitle = _sectionTable[textField.tag];
        if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_DATA_SECTION]) {
            [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:textField.text];
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_HEIGHT_SECTION]) {
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            BOOL result = YES;
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                if ([textField.text integerValue] < 2) {
                    textField.text = @"2";
                    result = NO;
                } else if ([textField.text integerValue] > 127) {
                    textField.text = @"127";
                    result = NO;
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_OMNI_DIRECTIONAL]) {
                if ([textField.text integerValue] < 33) {
                    textField.text = @"33";
                    result = NO;
                } else if ([textField.text integerValue] > 255) {
                    textField.text = @"255";
                    result = NO;
                }
            } else {
                if ([textField.text integerValue] != 0) {
                    textField.text = @"0";
                    result = NO;
                }
            }
            [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:textField.text];
            return result;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_COLUMN_SECTION]) {
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            BOOL result = YES;
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                if ([textField.text integerValue] <= 0) {
                    textField.text = @"0";
                    result = NO;
                } else if ([textField.text integerValue] > 30) {
                    textField.text = @"30";
                    result = NO;
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_EXPANDED_STACKED]) {
                if ([textField.text integerValue] < 2) {
                    textField.text = @"2";
                    result = NO;
                } else if ([textField.text integerValue] > 20) {
                    textField.text = @"20";
                    result = NO;
                }
            } else {
                if ([textField.text integerValue] != 0) {
                    textField.text = @"0";
                    result = NO;
                }
            }
            [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:textField.text];
            return result;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ROW_SECTION]) {
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            BOOL result = YES;
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                if ([textField.text integerValue] <= 0) {
                    textField.text = @"0";
                } else if ((0 < [textField.text integerValue]) && [textField.text integerValue] < 3) {
                    textField.text = @"3";
                    result = NO;
                } else if ([textField.text integerValue] > 90) {
                    textField.text = @"90";
                    result = NO;
                }
            } else {
                if ([textField.text integerValue] != 0) {
                    textField.text = @"0";
                    result = NO;
                }
            }
            [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:textField.text];
            return result;
        }
    }
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (0 <= textField.tag && textField.tag < _sectionTable.count) {
        NSString *sectionTitle = _sectionTable[textField.tag];
        if (([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_HEIGHT_SECTION])
            || ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_COLUMN_SECTION])
            || ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ROW_SECTION])) {
            NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:string];
            if ([[NSCharacterSet decimalDigitCharacterSet] isSupersetOfSet:characterSet]) {
                NSMutableString *inputText= [textField.text mutableCopy];
                [inputText replaceCharactersInRange:range withString:string];
                return YES;
            } else {
                return NO;
            }
        } else {
            NSMutableString *inputText= [textField.text mutableCopy];
            [inputText replaceCharactersInRange:range withString:string];
            return YES;
        }
    }
    return YES;
}

#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    if (0 <= indexPath.section && indexPath.section <= _sectionTable.count) {
        NSString *sectionTitle = _sectionTable[indexPath.section];
        _sectionIndex = indexPath.section;
        if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_TYPE_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_TYPE_TABLE; i++) {
                [valueData addObject:TWO_DIMENSION_BARCODE_TYPE_TABLE[i]];
                if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_TYPE_TABLE[i]]) {
                    _viewController.currentValueIndex = i;
                }
            }
            _viewController.tableData = valueData;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODE_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_QR_CODE]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_QR_CODE_MODEL_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_QR_CODE_MODEL_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_QR_CODE_MODEL_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_MODE_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_PDF417_MODE_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_PDF417_MODE_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_DATA_MATRIX]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_MAXI_CODE]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            } else {
                [valueData addObject:TWO_DIMENSION_BARCODE_MODE_NONE];
                _viewController.currentValueIndex = 0;
            }
            _viewController.tableData = valueData;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_MAXI_CODE]) {
                [valueData addObject:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
                _viewController.currentValueIndex = 0;
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_MODULE_SIZE_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            } else {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            }
            _viewController.tableData = valueData;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ERROR_CORRECT_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_QR_CODE]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_TABLE; i++) {
                    [valueData addObject:TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_TABLE[i]];
                    if ([cell.textLabel.text isEqualToString:TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_TABLE[i]]) {
                        _viewController.currentValueIndex = i;
                    }
                }
            } else {
                [valueData addObject:TWO_DIMENSION_BARCODE_ERROR_CORRECT_NONE];
                _viewController.currentValueIndex = 0;
            }
            _viewController.tableData = valueData;
        }
    }
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    if (0 <= indexPath.section && indexPath.section <= _sectionTable.count) {
        NSString *sectionTitle = _sectionTable[indexPath.section];
        if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_TYPE_SECTION]) {
            return YES;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODE_SECTION]) {
            return YES;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION]) {
            return YES;
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ERROR_CORRECT_SECTION]) {
            return YES;
        } else {
            return NO;
        }
    } else {
        return NO;
    }
}

#pragma mark - Button Action
- (IBAction)printButtonOnClicked:(id)sender {
    [self startLoadingView];
    dispatch_async([PrinterManager getDispatchQueue], ^{
        NSInteger type = [ValueManager convert2DBarcodeTypeStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE]];
        NSString *text = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA];
        NSInteger mode = [ValueManager convert2DBarcodeModeStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE]];
        NSInteger moduleSize = [ValueManager convert2DBarcodeModuleSizeStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE]];
        NSInteger moduleHeight = [[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT] integerValue];
        NSInteger column = [[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN] integerValue];
        NSInteger row = [[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW] integerValue];
        NSInteger errorCorrect = [ValueManager convert2DBarcodeErrorCorrectStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT]];
        BOOL result = [PrinterManager print2DCode:type text:text mode:mode moduleSize:moduleSize moduleHeight:moduleHeight column:column row:row errorCorrect:errorCorrect];
        [self stopLoadingView];
        if (result == NO) {
            [self showMessageBox:@"" message:[NSString stringWithFormat:@"%@%@", @"Attempt to print 2DCode failed.\n ErrorCode : ", [PrinterManager getErrorCodeText]]];
        }
    });
}

- (IBAction)closeButtonOnClicked:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - Private
- (void)initIndicatorView {
    _indicatorView = [[NSBundle mainBundle] loadNibNamed:@"IndicatorView" owner:self options:nil][0];
    _indicatorView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    _indicatorView.hidden = YES;
    [self.view addSubview:_indicatorView];
}

- (void)setDefaultValue {
    if ([[ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE] length] == 0) {
        [[NSUserDefaults standardUserDefaults] setObject:TWO_DIMENSION_BARCODE_TYPE_QR_CODE forKey:KEY_TYPE_2D_BARCODE_TYPE];
        [[NSUserDefaults standardUserDefaults] setObject:TWO_DIMENSION_BARCODE_QR_CODE_MODEL_2 forKey:KEY_TYPE_2D_BARCODE_MODE];
        [[NSUserDefaults standardUserDefaults] setObject:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT forKey:KEY_TYPE_2D_BARCODE_MODULE_SIZE];
        [[NSUserDefaults standardUserDefaults] setObject:TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_L forKey:KEY_TYPE_2D_BARCODE_ERROR_CORRECT];
        [[NSUserDefaults standardUserDefaults] setObject:@"ABC0123456789" forKey:KEY_TYPE_2D_BARCODE_DATA];
        [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT];
        [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:KEY_TYPE_2D_BARCODE_COLUMN];
        [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:KEY_TYPE_2D_BARCODE_ROW];
    }
}

- (void)reloadTableView {
    if (0 <= _sectionIndex && _sectionIndex < _sectionTable.count) {
        NSString *sectionTitle = _sectionTable[_sectionIndex];
        if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_TYPE_SECTION]) {
            for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_TYPE_TABLE; i++) {
                if (_viewController.currentValueIndex == i) {
                    NSString *new2DBarcodeType = TWO_DIMENSION_BARCODE_TYPE_TABLE[i];
                    NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
                    if ([current2DBarcodeType isEqualToString:new2DBarcodeType] == NO) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE value:new2DBarcodeType];
                        [self initSectionTable];
                        [self reloadDefaultValue];
                        break;
                    }
                }
            }
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODE_SECTION]) {
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_QR_CODE]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_QR_CODE_MODEL_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_QR_CODE_MODEL_TABLE[i]];
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_MODE_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_PDF417_MODE_TABLE[i]];
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_DATA_MATRIX]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_TABLE[i]];
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_MAXI_CODE]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_TABLE[i]];
                    }
                }
            } else {
                [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_MODE_NONE];
            }
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION]) {
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_MAXI_CODE]) {
                [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_MODULE_SIZE_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE[i]];
                    }
                }
            } else {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_TABLE[i]];
                    }
                }
            }
        } else if ([sectionTitle isEqualToString:TWO_DIMENSION_BARCODE_ERROR_CORRECT_SECTION]) {
            NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
            if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_QR_CODE]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_TABLE[i]];
                    }
                }
            } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
                for (int i = 0; i < SIZE_OF_TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_TABLE; i++) {
                    if (_viewController.currentValueIndex == i) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_TABLE[i]];
                    }
                }
            } else {
                [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_ERROR_CORRECT_NONE];
            }
        }
    }
    _sectionIndex = -1;
    [self.tableView reloadData];
}

- (void)reloadViewSize {
    _frameWidth = (NSInteger)self.view.bounds.size.width;    
    [self.tableView reloadData];
}

- (void)addKeyboardNotification {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    _footerSize = self.tableView.superview.frame.size.height - self.tableView.frame.size.height;
}

- (void)removeKeyboardNotification {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillShow:(NSNotification *)aNotification {
    CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    float keyboardHeight = keyboardRect.size.height;
    self.tableView.frame = CGRectMake(0, 0, self.tableView.frame.size.width, (self.tableView.superview.frame.size.height - keyboardHeight));
}

- (void)keyboardWillHide:(NSNotification *)aNotification {
    self.tableView.frame = CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.superview.frame.size.height - _footerSize);
}

- (void)startLoadingView {
    dispatch_async(dispatch_get_main_queue(), ^{
        self->_indicatorView.hidden = NO;
    });
}

- (void)stopLoadingView {
    dispatch_async(dispatch_get_main_queue(), ^{
        self->_indicatorView.hidden = YES;
    });
}

- (void)showMessageBox:(NSString *)title message:(NSString *)message {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertController *alertController =  [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        }]];
        [self presentViewController:alertController animated:YES completion:nil];
    });
}

- (void)reloadDefaultValue {
    NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
    if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_QR_CODE]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:@"ABC0123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_QR_CODE_MODEL_1];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_QR_ERROR_CORRECT_L];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:@"ABC0123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_PDF417_MODE_STANDARD];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:@"10"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_PDF417_ERROR_CORRECT_0];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_DATA_MATRIX]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:@"ABC0123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_DATA_MATRIX_MODE_AUTO];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_ERROR_CORRECT_NONE];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_MAXI_CODE]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:@"122333444455555ABC0123456789DEF"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_MAXI_CODE_MODE_2];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_ERROR_CORRECT_NONE];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_STACKED]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:@"1230123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_MODE_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_ERROR_CORRECT_NONE];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_OMNI_DIRECTIONAL]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:@"1230123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_MODE_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:@"33"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_ERROR_CORRECT_NONE];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_EXPANDED_STACKED]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_DATA value:@"01173500538500163202000150"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODE value:TWO_DIMENSION_BARCODE_MODE_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_SIZE value:TWO_DIMENSION_BARCODE_MODULE_SIZE_DEFAULT];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_MODULE_HEIGHT value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_COLUMN value:@"2"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ROW value:@"0"];
        [ValueManager setCurrentStringValue:KEY_TYPE_2D_BARCODE_ERROR_CORRECT value:TWO_DIMENSION_BARCODE_ERROR_CORRECT_NONE];
    }
}

- (void)initSectionTable {
    NSString *current2DBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_2D_BARCODE_TYPE];
    if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_QR_CODE]) {
        _sectionTable = @[
            TWO_DIMENSION_BARCODE_TYPE_SECTION,
            TWO_DIMENSION_BARCODE_DATA_SECTION,
            TWO_DIMENSION_BARCODE_MODE_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION,
            TWO_DIMENSION_BARCODE_ERROR_CORRECT_SECTION
        ];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_TYPE_PDF417]) {
        _sectionTable = @[
            TWO_DIMENSION_BARCODE_TYPE_SECTION,
            TWO_DIMENSION_BARCODE_DATA_SECTION,
            TWO_DIMENSION_BARCODE_MODE_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_HEIGHT_SECTION,
            TWO_DIMENSION_BARCODE_COLUMN_SECTION,
            TWO_DIMENSION_BARCODE_ROW_SECTION,
            TWO_DIMENSION_BARCODE_ERROR_CORRECT_SECTION
        ];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_DATA_MATRIX]) {
        _sectionTable = @[
            TWO_DIMENSION_BARCODE_TYPE_SECTION,
            TWO_DIMENSION_BARCODE_DATA_SECTION,
            TWO_DIMENSION_BARCODE_MODE_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION
        ];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_MAXI_CODE]) {
        _sectionTable = @[
            TWO_DIMENSION_BARCODE_TYPE_SECTION,
            TWO_DIMENSION_BARCODE_DATA_SECTION,
            TWO_DIMENSION_BARCODE_MODE_SECTION
        ];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_STACKED]) {
        _sectionTable = @[
            TWO_DIMENSION_BARCODE_TYPE_SECTION,
            TWO_DIMENSION_BARCODE_DATA_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION
        ];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_OMNI_DIRECTIONAL]) {
        _sectionTable = @[
            TWO_DIMENSION_BARCODE_TYPE_SECTION,
            TWO_DIMENSION_BARCODE_DATA_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_HEIGHT_SECTION
        ];
    } else if ([current2DBarcodeType isEqualToString:TWO_DIMENSION_BARCODE_GS1_EXPANDED_STACKED]) {
        _sectionTable = @[
            TWO_DIMENSION_BARCODE_TYPE_SECTION,
            TWO_DIMENSION_BARCODE_DATA_SECTION,
            TWO_DIMENSION_BARCODE_MODULE_SIZE_SECTION,
            TWO_DIMENSION_BARCODE_COLUMN_SECTION
        ];
    }
    [self.tableView reloadData];    
}

@end
