//
//  DevicesPickerViewController.m
//  MiAlerts
//
//  Created by Mahammad on 12/10/14.
//  Copyright (c) 2014 Mahammad. All rights reserved.
//

#import "DevicesPickerViewController.h"

@interface DevicesPickerViewController ()

@end

@implementation DevicesPickerViewController
@synthesize contentArray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (id)setArray:(NSArray *)contents inFrame:(CGRect)pickerFrame
{
    //self =
    [super init];
    if (self) {
        contentArray = [NSArray arrayWithArray: contents];
        
        pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
        pickerView.showsSelectionIndicator = YES;
        pickerView.delegate = self;
        
        [self.view addSubview:pickerView];
    }
    return self;
}
- (id)initWithArray:(NSArray *)contents inFrame:(CGRect)pickerFrame
{
    //self =
    [super init];
    if (self) {
        contentArray = [NSArray arrayWithArray: contents];
        
        pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
        pickerView.showsSelectionIndicator = YES;
        pickerView.delegate = self;
        
        [self.view addSubview:pickerView];
    }
    return self;
}
-(void)setInitialPickerValueToRow:(int)i inComponent:(int)j animated:(BOOL)k{
    [pickerView selectRow:i inComponent:j animated:k];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
    if(contentArray == nil)
        return 0;
    return [contentArray count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if(contentArray == nil)
        return @"Empty";
    if([contentArray count]<= row)
        return @"Empty";
    return [contentArray objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if(self.delegatePicker == nil)
        return;
    [self.delegatePicker touchedPicker:[contentArray objectAtIndex:row]];
}

@end
