2015-01-04 1 views
0

하나의 스토리 보드에 2 개의 피커 뷰를 표시 할 수 없습니다. 나는 각각을 하나씩 얻을 수 있지만 두 가지가 아니다. 인식 할 수없는 선택기 이유 [JobLocation salesman]이 표시됩니다. [SalesLocation salesman]이어야합니다. 나는 그것을 이해할 수 없다. 인 부분 self.jobNo.inputView = [self jobPicker]은 이 아니지만 입니다. self.saleNo.inputView = [셀프 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

두 개의 배열을 변경하지 않고 itemsDownload에서 동일한 항목을 다운로드하면 해결할 수 있습니다. –

답변

1

itemsDownloaded에서 당신이 _feedItemsS_feedItemsJ 모두 같은 일을 할당하는 결과 모든 코드입니다. 둘 중 하나가 JobLocation 개체가되거나 둘 다 SalesLocation 개체가 될 것입니다. 다운로드 대상에 따라 다릅니다.

itemsDownloaded 안에 NSLog(@"Incoming array: %@", items); 번을 시도해 할당 된 것을 확인하십시오.

+0

에는이 itemsDownLoaded를 극복 할 수있는 방법이 있습니다. _feedItemsS = items; _feedItemsJ = items; –

+0

그것은'items' 안에있는 것에 달려 있습니다. 당신의 메소드는 두 번 이상 호출됩니다 (매번 다른 종류의 배열로) 또는'items'는 두 종류의 객체를 포함합니까? –

+0

예. 두 번 이상 호출 됨 –

관련 문제