2015-01-04 3 views
0

Кажется, я не могу получить 2 Picker Views, чтобы показать их в одной раскадровке. Я могу получить каждый из них индивидуально, но не два. Я получаю непризнанную причину выбора селектора [JobLocation salesman]. Это должно быть [SalesLocation salesman]. Я просто не могу понять. Часть с self.jobNo.inputView = [self jobPicker] работает , но не self.saleNo.inputView = [self salesPicker], см. Код ниже, где я получаю перерыв.Невозможно получить два сборщика Просмотр, чтобы показать в одной раскадровке

- (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; 
} 

здесь весь код

#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; 
     } 
} 

попытался массив это приводит

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>" 
) 
+0

есть обходной путь с itemsDownloaded те же элементы в itemsDownload без изменения двух массивов –

ответ

1

В itemsDownloaded вы назначая те же вещи как _feedItemsS и _feedItemsJ. Либо они оба будут JobLocation объектов, либо оба будут SalesLocation объектов в зависимости от того, что скачано.

Попробуйте NSLog(@"Incoming array: %@", items); внутри itemsDownloaded, чтобы увидеть, что назначается.

+0

есть ли способ преодолеть это itemsDownLoaded с _feedItemsS = items; _feedItemsJ = предметы; –

+0

Это зависит от того, что внутри 'items'. Вызывается ли ваш метод чаще, чем один раз (с разным типом массива каждый раз), или 'items' содержат оба вида объектов? –

+0

Да, он вызывается более одного раза –

Смежные вопросы