- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在编程方面没有太多经验,所以这是我的问题:
我正在尝试编写一个转换器应用程序。最后,您可以输入一个数字。然后我有两个组件UIPickerView
.使用第一个组件,您可以选择输入格式(例如 °Celcius)。使用第二个组件,您可以选择输出格式(例如°Fahrenheit),以便将°Celcius 转换为°Fahrenheit。
但我想添加更多单位(重量、能量等)。我希望它们显示在 UITableView
上.如果我在 UITableView
中选择某个单元格, UIPickerView
必须更新其委托(delegate)。更准确地说,包含单位名称(例如 eV、Joule、cal、erg 等)的数组必须以某种方式在 detailViewController
中实现。 (我有我的 UIPickerView
).
Đây là mã của tôi:
View Controller .h
#nhập
@interface ViewController : UIViewController
@property (strong,nonatomic) IBOutlet UIPickerView *EinheitenPicker;
@property (weak,nonatomic) IBOutlet UITableView *EinheitenTableView;
@kết thúc
#import "ViewController.h"
@interface ViewController ()
{
NSArray *EinheitenNameArray;
}
@kết thúc
@implementation ViewController
@synthesize EinheitenPicker,EinheitenTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
EinheitenNameArray=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AlleEinheiten" ofType:@"plist"]];
[self.EinheitenTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
[self.EinheitenTableView.delegate tableView:self.EinheitenTableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark UItableView Delegate
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return EinheitenNameArray.count;
}
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier=@"CellId";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[[EinheitenNameArray objectAtIndex:indexPath.row] objectForKey:@"Titel"];
return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSLog(@"Chosen:%@",self.EinheitenPicker);
[self.storyboard instantiateViewControllerWithIdentifier:@"TestId"];
[self.EinheitenPicker reloadAllComponents];
}
#pragma mark UIPickerView Methods
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSIndexPath *selectedIndexPath=[self.EinheitenTableView indexPathForSelectedRow];
NSArray *units=[[EinheitenNameArray objectAtIndex:selectedIndexPath.row] objectForKey:@"Einheiten"];
if (component == 0) {
return units.count;
}
return units.count;
}
- (NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSIndexPath *selectedIndexPath=[self.EinheitenTableView indexPathForSelectedRow];
NSArray *units=[[EinheitenNameArray objectAtIndex:selectedIndexPath.row] objectForKey:@"Einheiten"];
return [units objectAtIndex:row];
}
@kết thúc
1 Câu trả lời
如果我没记错的话,你正在寻找这样的东西。
要拥有它,您必须按如下方式实现 UIPickerView 方法
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
NSIndexPath *selectedIndexPath=[self.unitsTableView indexPathForSelectedRow];
NSArray *units=[[unitDataArray objectAtIndex:selectedIndexPath.section] objectForKey:@"units"];
return units.count;
}
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
NSIndexPath *selectedIndexPath=[self.unitsTableView indexPathForSelectedRow];
NSArray *units=[[unitDataArray objectAtIndex:selectedIndexPath.section] objectForKey:@"units"];
return [units objectAtIndex:row];
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self.unitPicker reloadAllComponents];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
unitDataArray=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource: ofType:@"plist"]];
[self.unitsTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
[self.unitsTableView.delegate tableView:self.unitsTableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return unitDataArray.count;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSDictionary *unitData=[unitDataArray objectAtIndex:section];
return [[unitData objectForKey:@"units"] count];
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier=@"CellId";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[[[unitDataArray objectAtIndex:indexPath.section] objectForKey:@"units"] objectAtIndex:indexPath.row];
return cell;
}
-(NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
NSDictionary *unitData=[unitDataArray objectAtIndex:section];
return [unitData objectForKey:@"title"];
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self.unitPicker reloadAllComponents];
}
@implementation ViewController
@synthesize unitPicker,unitsTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
unitDataArray=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AllUnits" ofType:@"plist"]];
[self.unitsTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
[self.unitsTableView.delegate tableView:self.unitsTableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark UItableView Delegate
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return 1;//Changes 1
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return unitDataArray.count;//Changes 2
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier=@"CellId";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[[unitDataArray objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self.unitPicker reloadAllComponents];
}
#pragma mark UIPicker View Methods
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;//Changes 3
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
NSIndexPath *selectedIndexPath=[self.unitsTableView indexPathForSelectedRow];
NSArray *units=[[unitDataArray objectAtIndex:selectedIndexPath.row] objectForKey:@"units"];//Changes 4
return units.count;
}
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
NSIndexPath *selectedIndexPath=[self.unitsTableView indexPathForSelectedRow];
NSArray *units=[[unitDataArray objectAtIndex:selectedIndexPath.row] objectForKey:@"units"];//Changes 5
return [units objectAtIndex:row];
}
@kết thúc
#nhập
@interface ViewController : UIViewController
@property (weak,nonatomic) IBOutlet UIPickerView *unitPicker;
@property (weak,nonatomic) IBOutlet UITableView *unitsTableView;
@kết thúc
关于ios - UIPickerView 依赖于 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16648459/
我正在编写一个汽车租赁应用程序,用户必须指定取车和还车位置。 第一步,用户必须选择取货/返回办公室的区域/区域。选择区域后,他必须从该区域可用的办事处列表中进行选择。 为了选择办公室,我使用了 4 个
我正在尝试创建一个文本框,当选择该文本框时,UIPickerView 将打开并提供可供选择的选项。选择后,UIPickerView 将隐藏,所选项目将显示在文本框中。当我运行此程序时,数组中的第一个元
我有多个 UIPickerView 的问题,我在 UICollectionView 上有 8 个,当我滚动第一个 PickerView 和第五个 PickerView 时,它开始自行滚动并采用与第一个
我正在阅读一本 Swift OOP 书籍,我理解实例方法具有将在函数中使用的参数的想法。不清楚的是,在遵循 UIPickerViews 和 UITableViews 的在线教程时,有些方法将 UIPi
我有两个不同的 UIPickerView用户选择第一个 UIPickerView来自 didSelectRow第一个选择器,我得到第二个的输入 UIPickerView .我尝试为单个选择器设置标签,
函数 pickerView() 在 ViewLoad 上调用的代码 private func createPickerView(){ picker = UIPickerView(frame:
我创建了 UIPickerView 如下。现在我想让它 resignFirstResponder 如果用户在其他地方点击然后 UIPickerView 我怎么能实现呢。我已经按照以下方式创建了 UIP
我的 View Controller 中有两个 UIPickerview,pickerView1 和 pickerView2。 我在这里想要实现的是,当我从 pickerView1 中选择一个字符串时
我们正在使用 UIPickerView允许用户从选项列表中进行选择。我们正在添加 UIPickerView作为容器 UIView 的 subview 。然后我们将一个 UITapGestureReco
好吧,我不知道如何处理这个问题。 我有一个 UITextField,我根据 XML 文件的定义将其动态添加到 UITableView,在 XML 文件中,我可以将列表指定为其中一种数据类型,然后我所做
我现在有2个UIPickerView,以后想再添加3个,代码如下: -(void)viewDidLoad{ Pos_x = 5; Pos_y = 70; for (i= 0; i<2; i++) {
UIPickerView 的 selectRow:inComponent:animated:调用pickerView:didSelectRow:inComponent: ? 否则,我可以自己打电话吗?
我有两个按钮,打开一个 UIPickerView @IBOutlet weak var convertFromButton: UIButton! @IBOutlet weak var convertT
祝大家有美好的一天 我尝试在主题行中解释我的查询。据我了解,从代码中看到,所有 pickerview 都在 ViewDidLoad() 中初始化,这意味着它们都有自己的数据集。作为数据验证的一部分(在
我试图在 PickerView 中显示血型,但由于某些原因,选项仅显示为问号! 这是我的代码: class RegisterViewController: UIViewController,
我正在尝试将工具栏添加到 UIPicker . 我已经看到正确的方法是这样: UIToolbar* toolbarWeight= [[UIToolbar alloc] initWithFrame:CG
我将如何向 uipickerview 添加手势事件来更改选项卡?我必须创建一个自定义类,但是,我不知道如何处理 uipickerview。我当前在 uiviews 中存在手势来执行此操作,但我在使用
我想做的是: 显示了一个 UIPickerView。如果用户触摸选定的行,则该行将被锁定(它是多组件选择器),并且其他组件可以自由旋转。如果该行已被锁定并且用户触摸了锁定的行,则该行将被解锁并可以自由
我有两种看法。第一个:第一个 View Controller 第二:SecondViewController FirstView Controller 是我的 UINavigationControll
使用 UISegmentedControl,您可以在不选择任何内容的情况下启动它。如何使用 UIPickerView 做到这一点?看起来显示默认为索引 0。 谢谢 最佳答案 选择器轮必须停留在某些值上
Tôi là một lập trình viên xuất sắc, rất giỏi!