我有UIPickerView有两个组件。我想要第一个组件的动作和第二个自动移动。
不要提供- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
答案 0 :(得分:2)
// WPSecondViewController.h
// test
//
// Created by VASANTH K on 21/01/14.
//
#import <UIKit/UIKit.h>
@interface WPSecondViewController : UIViewController<UIPickerViewDataSource,UIPickerViewDelegate>
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
@end
不要忘记将选择器的delegate
和datasource
设置为viewController
。
//
// WPSecondViewController.m
// test
//
// Created by VASANTH K on 21/01/14.
//
#import "WPSecondViewController.h"
@interface WPSecondViewController ()
@end
此代码简单滚动一个组件以匹配另一个组件行。
@implementation WPSecondViewController
- (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 -
#pragma mark PickerView DataSource
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return 20;
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [NSString stringWithFormat:@"%d_%d",row,component];
}
#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
if(component==0)
{
[self.picker selectRow:row inComponent:1 animated:YES];
}
else
{
[self.picker selectRow:row inComponent:0 animated:YES];
}
}
@end