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 原文来自破船的分享 原文作者是开发界中知晓度相当高 ...
随机推荐
- NSArray进行汉字排序
由于NSArray并不直接支持对汉字的排序,这就要通过将汉字转换成拼音完毕按A~Z的排序,这看起来是个头疼的问题.由于牵扯到汉字转为拼音,kmyhy给出一个较易实现的方法,获取汉字的首字的首字母,如将 ...
- 排名前16的Java工具类
原文:https://www.jianshu.com/p/9e937d178203 在Java中,工具类定义了一组公共方法,这篇文章将介绍Java中使用最频繁及最通用的Java工具类.以下工具类.方法 ...
- linux 下查看硬盘分区类型
可以用 df 这个命令 具体 要 man df 仔细看看 实例 [root@localhost mnt]# df -Th文件系统 类型 容量 已用 可用 已用% 挂载点/dev ...
- 关于面试总结11-selenium面试题
前言 面试web自动化必然会问到selenium,问selenium相关的问题定位是最基本的,也是自动化的根本,所以面试离不开元素定位问题. 之前看到招聘要求里面说"只会复制粘贴xpath的 ...
- JForum 源码分析
怎么才算好的源码分析呢?当然我这个肯定不算.我想大概分为几个层面吧,写写注释那算最基本的了,写写要点思路和难点,算是还不错拉,再难的就是跳出源码举一反三,形成自己的一套思路吧.好好努力吧. 这次针对的 ...
- sharepoint 2013 网站集解锁
前言 最近碰到这样的一个问题,就是SharePoint 站点备份(Backup-SPSite)的时候,速度特别慢,然后网站变成只读状态(备份过程中只读属于正常现象).但是,自己手欠把备份命令的Powe ...
- Asp.Net WebApi开启Session回话
一.在WebApi项目中默认没有开启Session回话支持.需要在Global中的Init()方法中指定会员需要支持的类型 public class WebApiApplication : Syste ...
- 第三方IDC性能测评主要指标
弹性计算性能弹性计费模式就是 "即用即付 ",最小单位可以按小时来计算.随着云计算负载的增长,企业购买服务器带宽时的资源. 1.弹性计算性能 弹性计费模式就是"即 ...
- 让Android Preference Summary中实时显示内容变更
Android中提供的Preference可以保存用户的喜好设置.在启明星安卓版员工通讯录里,有一个地方保存用户输入的URL就是用的Preference. 但是Preference默认显示的是Summ ...
- webrequest HttpWebRequest webclient/HttpClient
webrequest(abstract类,不可直接用) <--- (继承)---- HttpWebRequest(更好的控制请求) <--- (继承)---- webclient (简单快 ...