iOS开发技巧 - 使用UIPickerView来选择值
(Swift)
import UIKit class ViewController: UIViewController, UIPickerViewDataSource {
var picker: UIPickerView! override func viewDidLoad() {
super.viewDidLoad() picker = UIPickerView() // select the current view controller as the data source of the picker view
picker.dataSource = self
picker!.delegate = self picker.center = view.center
view.addSubview(picker)
} /*
Implemented some of the methods of the UIPickerViewDataSource protocol
*/ // returns the number of 'columns' to display
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
if pickerView == picker {
return
}
return
} // returns the number of rows in each component
func pickerView(pickerView: UIPickerView,
numberOfRowsInComponent component: Int) -> Int {
if pickerView == picker {
return
}
return
}
} func pickerView(pickerView: UIPickerView,
titleForRow row: Int,
forComponent component: Int) -> String! {
return "\(row + 1)"
}
(Objective-C)
@interface ViewController () <UIPickerViewDataSource, UIPickerViewDelegate> @property (nonatomic, strong) UIPickerView *myPicker; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.myPicker = [[UIPickerView alloc] init]; // select the current view controller as the data source of the picker view
self.myPicker.dataSource = self;
self.myPicker.delegate = self; self.myPicker.center = self.view.center;
[self.view addSubview:self.myPicker];
} /*
Implemented some of the methods of the UIPickerViewDataSource protocol
*/ - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
if ([pickerView isEqual:self.myPicker]){
return ;
}
return ;
}
- (NSInteger) pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
if ([pickerView isEqual:self.myPicker]){
return ;
}
return ;
} - (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
if ([pickerView isEqual:self.myPicker]) {
/* Row is zero-based and we want the first row (with index 0)
to be rendered as Row 1, so we have to +1 every row index */ return [NSString stringWithFormat:@"Row %ld", (long)row + ];
} return nil;
}
iOS开发技巧 - 使用UIPickerView来选择值的更多相关文章
- iOS开发技巧 - 使用UISlider来调整值的范围
(Swift) import UIKit class ViewController: UIViewController { var slider: UISlider! func sliderValue ...
- iOS开发技巧 - 使用UIDatePicker来选择日期和时间
(Swift) import UIKit class ViewController: UIViewController { var datePicker: UIDatePicker! func dat ...
- iOS开发技巧系列---详解KVC(我告诉你KVC的一切)
KVC(Key-value coding)键值编码,单看这个名字可能不太好理解.其实翻译一下就很简单了,就是指iOS的开发中,可以允许开发者通过Key名直接访问对象的属性,或者给对象的属性赋值.而不需 ...
- 【转】几点 iOS 开发技巧
[译] 几点 iOS 开发技巧 原文:iOS Programming Architecture and Design Guidelines 原文来自破船的分享 原文作者是开发界中知晓度相当高的 Mug ...
- iOS开发技巧
一.寻找最近公共View 我们将一个路径中的所有点先放进 NSSet 中.因为 NSSet 的内部实现是一个 hash 表,所以查找元素的时间复杂度变成了 O(1),我们一共有 N 个节点,所以总时间 ...
- iOS开发技巧系列---使用链式编程和Block来实现UIAlertView
UIAlertView是iOS开发过程中最常用的控件之一,是提醒用户做出选择最主要的工具.在iOS8及后来的系统中,苹果更推荐使用UIAlertController来代替UIAlertView.所以本 ...
- iOS开发技巧 -- 复用代码片段
如果你是一位开发人员在开发过程中会发现有些代码无论是在同一个工程中还是在不同工程中使用率会很高,有经验的人会直接封装在一个类里,或者写成一个宏定义或者把这些代码收集起来,下次直接使用,或者放到xcod ...
- iOS开发技巧 - Size Class与iOS 8多屏幕适配(一)
0. 背景: 在iOS开发中,Auto Layout(自动布局)能解决大部分的屏幕适配问题. 但是当iPhone 6和iPhone 6 Plus发布以后, Auto Layout已经不能解决复杂的屏幕 ...
- 几点iOS开发技巧
转自I'm Allen的博客 原文:iOS Programming Architecture and Design Guidelines 原文来自破船的分享 原文作者是开发界中知晓度相当高 ...
随机推荐
- JAVA各种系统架构图及其简介
1.spring架构图 Spring是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为J2EE应用程序开发提供集成的框 ...
- TrinityCore3.3.5环境搭建
说起TrinityCore,可能知道的人不多,但是说起MaNGOS(芒果)知道的人应该就不少了.MaNGOS是一个魔兽私服服务器端,TrinityCore继承自TrinityCore并且做了优化,一直 ...
- 在ASP.NET Web API中使用OData的Containment
通常情况下,一个OData的EDM(Entity Data Model)在配置的时候定义了,才可以被查询或执行各种操作.比如如下: builder.EntitySet<SomeModel> ...
- GDI+用PNG图片做半透明异型窗口
{*******************************************************} { ...
- Maven 使用了一个标准的目录结构和一个默认的构建生命周期。
Maven 使用了一个标准的目录结构和一个默认的构建生命周期. 约定优于配置 当创建 Maven 工程时,Maven 会创建默认的工程结构.开发者只需要合理的放置文件,而在 pom.xml 中不再需要 ...
- having只用来在group by之后,having不可单独用,必须和group by用。having只能对group by的结果进行操作
having只能对group by的结果进行操作 having只能对group by的结果进行操作 having只能对group by的结果进行操作 having只用来在group by之后,havi ...
- java根据模板文件导出pdf
原文:https://www.cnblogs.com/wangpeng00700/p/8418594.html 在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模 ...
- xcode 不能选择模拟器
重新安装了xcode后,程序无法运行,不能选择模拟器 或者 设备? 1.你之所以选择不了模拟器或者设备,是因为你工程中的iOS Deployment Target设置不对.比如你装的是xcode4.0 ...
- Objective-C市场占有率排名升至第4位
TIOBE近日公布了2012年4月份的编程语言排行榜,终于不出小编所料,在上个月的编程语言排行榜中说过的“编程语言的王者之争不久很可能会发生改变”实现了,一方面是Java在上几个月中一直属于下滑状态, ...
- .NET:强签名程序集的加载问题 之 版本重定向
背景 多数解决方案会包含多个项目,某些支持插件架构的解决方案中,更是包含多个插件项目,这些项目会使用一些第三方NuGet Packages,如果管理不慎,解决方案中会出现多个版本的引用,这在编译期间不 ...