【发布时间】:2014-03-19 17:34:02
【问题描述】:
作为 Objective-C 课程的一部分,我正在开发 Country and Capitals 应用程序。
到目前为止,当用户在选择器中选择一个国家时,相关的首都会显示在下面的标签中。
我的问题是如何编码,以便只有在用户单击“获取资本”按钮后才会显示首都。
我知道这似乎效率较低,但知道如何做会很有用!
countryNames =[[NSArray alloc]initWithObjects:@"England",
@"United States",
@"India",
@"Australia",
@"Canada",
@"France",
@"The Netherlands",
@"South Africa",nil];
cityNames =[[NSArray alloc]initWithObjects:@"London",
@"Washington DC",
@"Dehli",
@"Canberra",
@"Ottawa",
@"Paris",
@"Amsterdam",
@"Cape Town",nil];
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
lblcapitalCity.text =[cityNames objectAtIndex:row];
}
// 不确定如何在点击按钮后只显示城市
【问题讨论】:
-
不要在 didSelectRow 中做任何事情。创建一个按钮并附加一个动作,根据
[pickerView selectedRowInComponent:0]分配 lblCapitalCity.text -
感谢@David,但在阅读您的解决方案后我仍然不明白。我应该对:-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 进行哪些更改,我应该在这里编写什么代码:- (IBAction)getCapitalButton:(id)sender {}
标签: ios objective-c uibutton uipickerview