UIPickerView 使用

2023-10-31 04:30
文章标签 使用 uipickerview

本文主要是介绍UIPickerView 使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

//初始化 pickerView
-(void)initPickerView{pickerArray = [NSArray arrayWithObjects:@"顺丰",@"申通",@"韵达",@"圆通",@"天天",@"全峰",@"中通",@"百世汇通", nil];logisticsPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 568, 320, 180)];logisticsPicker.delegate = self; //绑定事件logisticsPicker.dataSource = self; //绑定数据元[logisticsPicker setBackgroundColor:[UIColor whiteColor]]; [self.view addSubview:logisticsPicker];[self.view bringSubviewToFront:logisticsPicker];//将视图放置最前面
}
//每行显示的个数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{return 1;
}
//显示多少行
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{return [pickerArray count];
}
//每行显示的标题名称
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{return [pickerArray objectAtIndex:row];
}//点击空白隐藏键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{[self.view endEditing:YES];[self inView];
}
//设置隐藏动画
- (void)popView {CGContextRef context = UIGraphicsGetCurrentContext();[UIView beginAnimations:nil context:context];[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];[UIView setAnimationDuration:0.6];//动画时间长度,单位秒,浮点数[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];self.logisticsPicker.frame = CGRectMake(0, 400, 320, 180);[UIView setAnimationDelegate:self];// 动画完毕后调用animationFinished
//    [UIView setAnimationDidStopSelector:@selector(animationFinished)];[UIView commitAnimations];
}
//设置弹出动画
- (void)inView {CGContextRef context = UIGraphicsGetCurrentContext();[UIView beginAnimations:nil context:context];[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];[UIView setAnimationDuration:0.6];//动画时间长度,单位秒,浮点数self.logisticsPicker.frame = CGRectMake(0, 568, 320, 180);[UIView setAnimationDelegate:self];// 动画完毕后调用animationFinished
//    [UIView setAnimationDidStopSelector:@selector(animationFinished)];[UIView commitAnimations];
}
-(void)animationFinished{NSLog(@"动画结束!");
}
//绑定 页面点击事件
-(IBAction)logisticsPickerBtn:(id)sender{if(lpEntity){[self.view endEditing:YES];[self popView];}else{chvc = [[CalendarHomeViewController alloc]init];chvc.calendartitle = @"出行日期";[chvc setAirPlaneToDay:365 ToDateforString:nil];//飞机初始化方法chvc.calendarblock = ^(CalendarDayModel *model){logisticsName.text = [model toString];};[self.navigationController pushViewController:chvc animated:YES];}
}
//当你选中 pickerview 的某行时会调用该函数。
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {NSLog(@"You select row %ld",(long)row);logisticsName.text = [pickerArray objectAtIndex:row];
}

ps:这是我个人使用时用的,个人可根据自己的需求实际开发相关功能。



转载于:https://my.oschina.net/jack088/blog/512157

这篇关于UIPickerView 使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/312839

相关文章

如何使用C#串口通讯实现数据的发送和接收

《如何使用C#串口通讯实现数据的发送和接收》本文详细介绍了如何使用C#实现基于串口通讯的数据发送和接收,通过SerialPort类,我们可以轻松实现串口通讯,并结合事件机制实现数据的传递和处理,感兴趣... 目录1. 概述2. 关键技术点2.1 SerialPort类2.2 异步接收数据2.3 数据解析2.

详解如何使用Python提取视频文件中的音频

《详解如何使用Python提取视频文件中的音频》在多媒体处理中,有时我们需要从视频文件中提取音频,本文为大家整理了几种使用Python编程语言提取视频文件中的音频的方法,大家可以根据需要进行选择... 目录引言代码部分方法扩展引言在多媒体处理中,有时我们需要从视频文件中提取音频,以便进一步处理或分析。本文

使用Dify访问mysql数据库详细代码示例

《使用Dify访问mysql数据库详细代码示例》:本文主要介绍使用Dify访问mysql数据库的相关资料,并详细讲解了如何在本地搭建数据库访问服务,使用ngrok暴露到公网,并创建知识库、数据库访... 1、在本地搭建数据库访问的服务,并使用ngrok暴露到公网。#sql_tools.pyfrom

使用mvn deploy命令上传jar包的实现

《使用mvndeploy命令上传jar包的实现》本文介绍了使用mvndeploy:deploy-file命令将本地仓库中的JAR包重新发布到Maven私服,文中通过示例代码介绍的非常详细,对大家的学... 目录一、背景二、环境三、配置nexus上传账号四、执行deploy命令上传包1. 首先需要把本地仓中要

Spring Cloud之注册中心Nacos的使用详解

《SpringCloud之注册中心Nacos的使用详解》本文介绍SpringCloudAlibaba中的Nacos组件,对比了Nacos与Eureka的区别,展示了如何在项目中引入SpringClo... 目录Naacos服务注册/服务发现引⼊Spring Cloud Alibaba依赖引入Naco编程s依

Java springBoot初步使用websocket的代码示例

《JavaspringBoot初步使用websocket的代码示例》:本文主要介绍JavaspringBoot初步使用websocket的相关资料,WebSocket是一种实现实时双向通信的协... 目录一、什么是websocket二、依赖坐标地址1.springBoot父级依赖2.springBoot依赖

Java使用Mail构建邮件功能的完整指南

《Java使用Mail构建邮件功能的完整指南》JavaMailAPI是一个功能强大的工具,它可以帮助开发者轻松实现邮件的发送与接收功能,本文将介绍如何使用JavaMail发送和接收邮件,希望对大家有所... 目录1、简述2、主要特点3、发送样例3.1 发送纯文本邮件3.2 发送 html 邮件3.3 发送带

使用DeepSeek搭建个人知识库(在笔记本电脑上)

《使用DeepSeek搭建个人知识库(在笔记本电脑上)》本文介绍了如何在笔记本电脑上使用DeepSeek和开源工具搭建个人知识库,通过安装DeepSeek和RAGFlow,并使用CherryStudi... 目录部署环境软件清单安装DeepSeek安装Cherry Studio安装RAGFlow设置知识库总

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

Spring-AOP-ProceedingJoinPoint的使用详解

《Spring-AOP-ProceedingJoinPoint的使用详解》:本文主要介绍Spring-AOP-ProceedingJoinPoint的使用方式,具有很好的参考价值,希望对大家有所帮... 目录ProceedingJoinPoijsnt简介获取环绕通知方法的相关信息1.proceed()2.g