Peter Balsamo
Peter Balsamo

Reputation: 17

Can't get two picker View to show in one Storyboard

I can't seem to get 2 Picker Views to show in one Storyboard. I can get each one inividually but not two. I get unrecognized selector reason [JobLocation salesman]. It should be [SalesLocation salesman]. I just can't figure it out. The part with self.jobNo.inputView = [self jobPicker] works but not self.saleNo.inputView = [self salesPicker], see code below where i get break.

- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
        NSString *result = nil;

    if (pickerView.tag == 1) {
        itemS = _feedItemsS[row];
        return itemS.salesman;
    }
    else if(pickerView.tag == 2) {
        itemJ = _feedItemsJ[row];
        return itemJ.jobdescription; //I GET BREAK ON THIS LINE
    }
        return result;
}

here is all the code

#import "NewDataViewController.h"
#import "JobLocation.h"
#import "SalesLocation.h"


@interface NewDataViewController ()
{

SalesModel *_SalesModel; NSMutableArray *_feedItemsS;
JobModel *_JobModel; NSMutableArray *_feedItemsJ;

JobLocation *itemJ;
SalesLocation *itemS;
}

@end

@implementation NewDataViewController
@synthesize leadNo, active, date, first, last, company, address, city, state, zip, phone, aptDate, email, amount, spouse, callback, saleNo, jobNo, adNo, time, photo, comment;

- (void)viewDidLoad {
    [super viewDidLoad];

    if (self.date.text.length == 0) {
        NSDateFormatter *gmtDateFormatter = [[NSDateFormatter alloc] init];
        gmtDateFormatter.timeZone = [NSTimeZone localTimeZone];
        gmtDateFormatter.dateFormat = @"yyyy-MM-dd";
        NSString *dateString = [gmtDateFormatter stringFromDate:[NSDate date]];
        self.date.text = dateString;
    }

    self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width / 8;
    self.profileImageView.layer.borderWidth = 3.0f;
    self.profileImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.profileImageView.clipsToBounds = YES;

    UIBarButtonItem *saveItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(share:)];
    NSArray *actionButtonItems = @[saveItem];
    self.navigationItem.rightBarButtonItems = actionButtonItems;

    [[UITextView appearance] setTintColor:[UIColor grayColor]];
    [[UITextField appearance] setTintColor:[UIColor grayColor]];

    self.saleNo.inputView = [self salesPicker];
    self.jobNo.inputView = [self jobPicker];
   // self.adNo.inputView = [self createPicker];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.title =  @"New Data";
    [self.first becomeFirstResponder];
}

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

- (UIView *)salesPicker {
    _feedItemsS = [[NSMutableArray alloc] init];
    _SalesModel = [[SalesModel alloc] init];
    _SalesModel.delegate = self;
    [_SalesModel downloadItems];

    UIView *pickerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 175)];
    pickerView.backgroundColor = [UIColor orangeColor];

    UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 120)];
    picker.tag = 1;
    picker.dataSource = self;
    picker.delegate = self;
    picker.showsSelectionIndicator = YES;
    [picker reloadAllComponents];
    [pickerView addSubview:picker];
    [picker reloadAllComponents];

    return pickerView;
}

- (UIView *)jobPicker {
    _feedItemsJ = [[NSMutableArray alloc] init];
    _JobModel = [[JobModel alloc] init];
    _JobModel.delegate = self;
    [_JobModel downloadItems];

    UIView *pickerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 175)];
    pickerView.backgroundColor = [UIColor orangeColor];

    UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 120)];
    picker.tag = 2;
    picker.dataSource = self;
    picker.delegate = self;
    picker.showsSelectionIndicator = YES;
   [pickerView addSubview:picker];
    [picker reloadAllComponents];

    return pickerView;
}

-(void)itemsDownloaded:(NSMutableArray *)items
{   // This delegate method will get called when the items are finished downloading

    _feedItemsS = items;
    _feedItemsJ = items;
}

// The number of columns of data
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// The number of rows of data
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (pickerView.tag == 1) {
       return _feedItemsS.count;
    }
   else if(pickerView.tag == 2) {
       return _feedItemsJ.count;
    }
       return 0;
}

// The data to return for the row and component (column) that's being passed in
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
        NSString *result = nil;

    if (pickerView.tag == 1) {
        itemS = _feedItemsS[row];
        return itemS.salesman;
    }
    else if(pickerView.tag == 2) {
        itemJ = _feedItemsJ[row];
        return itemJ.jobdescription;
    }
        return result;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (pickerView.tag == 1) {
        itemS = _feedItemsS[row];
        self.saleNo.text = itemS.salesNo;
     }
    else if(pickerView.tag == 2) {
        itemJ = _feedItemsJ[row];
        self.jobNo.text = itemJ.jobNo;
      }
}

tried array this is results

MySQL[71361:10881622] Incoming array: (
    "<SalesLocation: 0x7ff88b7ae550>",
    "<SalesLocation: 0x7ff88b7ae630>",
    "<SalesLocation: 0x7ff88b7ae650>",
    "<SalesLocation: 0x7ff88b7ae690>",
    "<SalesLocation: 0x7ff88b7ae6b0>",
    "<SalesLocation: 0x7ff88b7ae670>",
    "<SalesLocation: 0x7ff88b7ae700>",
    "<SalesLocation: 0x7ff88b7ae770>",
    "<SalesLocation: 0x7ff88b7ae790>",
    "<SalesLocation: 0x7ff88b7ae7b0>",
    "<SalesLocation: 0x7ff88b7ae7d0>",
    "<SalesLocation: 0x7ff88b7ae6d0>",
    "<SalesLocation: 0x7ff88b7ae870>",
    "<SalesLocation: 0x7ff88b7ae890>",
    "<SalesLocation: 0x7ff88b7ae8b0>",
    "<SalesLocation: 0x7ff88b7ae8d0>",
    "<SalesLocation: 0x7ff88b7ae8f0>",
    "<SalesLocation: 0x7ff88b7ae720>"
)
2015-01-04 11:01:14.409 MySQL[71361:10881622] Incoming array: (
    "<JobLocation: 0x7ff88b7afdb0>",
    "<JobLocation: 0x7ff88b7afdd0>",
    "<JobLocation: 0x7ff88b7b0760>",
    "<JobLocation: 0x7ff88b7b07a0>",
    "<JobLocation: 0x7ff88b7b07c0>",
    "<JobLocation: 0x7ff88b7b0780>",
    "<JobLocation: 0x7ff88b7b0810>",
    "<JobLocation: 0x7ff88b7b0880>",
    "<JobLocation: 0x7ff88b7b08a0>",
    "<JobLocation: 0x7ff88b7b08c0>",
    "<JobLocation: 0x7ff88b7b08e0>",
    "<JobLocation: 0x7ff88b7b07e0>",
    "<JobLocation: 0x7ff88b7b0980>",
    "<JobLocation: 0x7ff88b7b09a0>",
    "<JobLocation: 0x7ff88b7b09c0>",
    "<JobLocation: 0x7ff88b7b09e0>",
    "<JobLocation: 0x7ff88b7b0a00>",
    "<JobLocation: 0x7ff88b7b0830>",
    "<JobLocation: 0x7ff88b7b0850>",
    "<JobLocation: 0x7ff88b7b0af0>",
    "<JobLocation: 0x7ff88b7b0b10>",
    "<JobLocation: 0x7ff88b7b0b30>",
    "<JobLocation: 0x7ff88b7b0b50>",
    "<JobLocation: 0x7ff88b7b0b70>",
    "<JobLocation: 0x7ff88b7b0b90>",
    "<JobLocation: 0x7ff88b7b0bb0>",
    "<JobLocation: 0x7ff88b7b0bd0>",
    "<JobLocation: 0x7ff88b7b0900>",
    "<JobLocation: 0x7ff88b7b0920>",
    "<JobLocation: 0x7ff88b7ae740>",
    "<JobLocation: 0x7ff888c2f130>",
    "<JobLocation: 0x7ff88b7acf00>",
    "<JobLocation: 0x7ff88b7ae030>",
    "<JobLocation: 0x7ff88b7adf70>",
    "<JobLocation: 0x7ff88b7ae0f0>",
    "<JobLocation: 0x7ff88b7ae050>",
    "<JobLocation: 0x7ff88b7ae070>",
    "<JobLocation: 0x7ff88b7b0940>",
    "<JobLocation: 0x7ff88b7b0960>",
    "<JobLocation: 0x7ff88b7ae190>",
    "<JobLocation: 0x7ff88b7ae1b0>",
    "<JobLocation: 0x7ff88b7ae1d0>"
)

Upvotes: 0

Views: 71

Answers (1)

Phillip Mills
Phillip Mills

Reputation: 31026

In itemsDownloaded you are assigning the same things to both _feedItemsS and _feedItemsJ. Either they are both going to be JobLocation objects or both will be SalesLocation objects depending on what's downloaded.

Try NSLog(@"Incoming array: %@", items); inside itemsDownloaded to see what's being assigned.

Upvotes: 1

Related Questions