(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来选择值的更多相关文章

  1. iOS开发技巧 - 使用UISlider来调整值的范围

    (Swift) import UIKit class ViewController: UIViewController { var slider: UISlider! func sliderValue ...

  2. iOS开发技巧 - 使用UIDatePicker来选择日期和时间

    (Swift) import UIKit class ViewController: UIViewController { var datePicker: UIDatePicker! func dat ...

  3. iOS开发技巧系列---详解KVC(我告诉你KVC的一切)

    KVC(Key-value coding)键值编码,单看这个名字可能不太好理解.其实翻译一下就很简单了,就是指iOS的开发中,可以允许开发者通过Key名直接访问对象的属性,或者给对象的属性赋值.而不需 ...

  4. 【转】几点 iOS 开发技巧

    [译] 几点 iOS 开发技巧 原文:iOS Programming Architecture and Design Guidelines 原文来自破船的分享 原文作者是开发界中知晓度相当高的 Mug ...

  5. iOS开发技巧

    一.寻找最近公共View 我们将一个路径中的所有点先放进 NSSet 中.因为 NSSet 的内部实现是一个 hash 表,所以查找元素的时间复杂度变成了 O(1),我们一共有 N 个节点,所以总时间 ...

  6. iOS开发技巧系列---使用链式编程和Block来实现UIAlertView

    UIAlertView是iOS开发过程中最常用的控件之一,是提醒用户做出选择最主要的工具.在iOS8及后来的系统中,苹果更推荐使用UIAlertController来代替UIAlertView.所以本 ...

  7. iOS开发技巧 -- 复用代码片段

    如果你是一位开发人员在开发过程中会发现有些代码无论是在同一个工程中还是在不同工程中使用率会很高,有经验的人会直接封装在一个类里,或者写成一个宏定义或者把这些代码收集起来,下次直接使用,或者放到xcod ...

  8. iOS开发技巧 - Size Class与iOS 8多屏幕适配(一)

    0. 背景: 在iOS开发中,Auto Layout(自动布局)能解决大部分的屏幕适配问题. 但是当iPhone 6和iPhone 6 Plus发布以后, Auto Layout已经不能解决复杂的屏幕 ...

  9. 几点iOS开发技巧

    转自I'm Allen的博客   原文:iOS Programming Architecture and Design Guidelines   原文来自破船的分享   原文作者是开发界中知晓度相当高 ...

随机推荐

  1. Android的学习之路(三)项目的启动过程和安装过程具体解释

    应用的安装和启动过程: 安装:第一步:java的编译器会把这个.java文件编译成.class文件           第二部:Android的SDK提供了一个dx工具,这个工具把.class文件转义 ...

  2. arcgispro 计算字段示例

    计算字段示例 round(!Shape.area!,1) 使用键盘输入值并不是编辑表中值的唯一方式.在某些情况下,为了设置字段值,可能要对单条记录甚至是所有记录执行数学计算.您可以对所有记录或选中记录 ...

  3. Winfrom固定Label宽度,根据文本动态改变Label的高度 z

    Label,要固定住宽度,然后根据文本的长度来动态改变高度,一开始去网上找解决方案,各种根据字体大小啊,字数啊来动态改变,但是效果却不怎么好.最后灵机一动,想起了偶尔用过一次的FlowLayoutPa ...

  4. PL/SQL 存储过程

    PL/SQL复习九 存储过程 无参数的存储过程: create or replace procedure out_time is begin dbms_output.put_line(to_char( ...

  5. 《iOS 7 应用开发实战详解》

    <iOS 7 应用开发实战详解> 基本信息 作者: 朱元波    管蕾 出版社:人民邮电出版社 ISBN:9787115343697 上架时间:2014-4-25 出版日期:2014 年5 ...

  6. 使用模拟对象(Mock Object)技术进行测试驱动开发

    敏捷开发 敏捷软件开发又称敏捷开发,是一种从上世纪 90 年代开始引起开发人员注意的新型软件开发方法.和传统瀑布式开发方法对比,敏捷开发强调的是在几周或者几个月很短的时间周期,完成相对较小功能,并交付 ...

  7. 微信二维码扫描无法下载APK文件的解决办法

  8. 谈谈Enter回车键提交表单那些事 回车搜索 enter搜索

    我们在做系统前端的时候,往往会用到form标签,采用jquery插件做表单验证.我们信誓旦旦的一位把一切都做好的时候,并且检查一遍又一遍的时候,意向不到的事情发生了,也许是出于一种意外,而这种意外我们 ...

  9. webrequest HttpWebRequest webclient/HttpClient

    webrequest(abstract类,不可直接用) <--- (继承)---- HttpWebRequest(更好的控制请求) <--- (继承)---- webclient (简单快 ...

  10. POJ 1719 Shooting Contest(二分图匹配)

    POJ 1719 Shooting Contest id=1719" target="_blank" style="">题目链接 题意:给定一个 ...