当前位置: 首页 > news >正文

邯郸网站设计注册seo关键词排名优化推荐

邯郸网站设计注册,seo关键词排名优化推荐,抖音代运营报价单(仅供参考),传奇世界官网UIPickerView 使用场景和功能UIPickerView遵循代理协议和数据源协议创建对象,添加代理必须实现的代理方法非必要实现的方法demo用到的其他函数提示 效果展示 使用场景和功能 UIPickerView 最常见的用途是作为选项选择器,允许用户从多个选项中选择一个。…

UIPickerView

  • 使用场景和功能
  • UIPickerView
    • 遵循代理协议和数据源协议
    • 创建对象,添加代理
    • 必须实现的代理方法
    • 非必要实现的方法
    • demo用到的其他函数
    • 提示
  • 效果展示

使用场景和功能

UIPickerView 最常见的用途是作为选项选择器,允许用户从多个选项中选择一个。UIPickerView 可以用于以滚动的方式展示大量数据,并允许用户通过滚动选择感兴趣的数据。一种很常见的用法是把各个数据以滚动的形式组成一个组合数据,比如年-月-日的日历或者时钟,以及省级-市级-区的地域 ;
这一部分的学习是参考学长的,用到了学长的plist文件 ;

UIPickerView

这个控件是iOS中自带的控件,使用方法类似于UItableview,所以就从UItableveiw的使用来分析了,这里跟着别人做了一个省级-市级-区的地域的小demo

遵循代理协议和数据源协议

#import <UIKit/UIKit.h>@interface ViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>
@property (nonatomic, strong) UIPickerView* pickerview ;
@property (nonatomic, strong) NSMutableArray* provinceArray ;
@property (nonatomic, strong) NSArray* cityArray ;
@property (nonatomic, strong) NSArray* areaArray ;
@end

创建对象,添加代理

self.pickerview = [[UIPickerView alloc] initWithFrame:CGRectMake(50, 100, 300, 200)] ;//类似于tableview,需要设置代理和数据源self.pickerview.delegate = self ;self.pickerview.dataSource = self ;[self.view addSubview:self.pickerview] ;

必须实现的代理方法

//组数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {return 3;
}
//行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {if (component == 0) {return [self.provinceArray count];} else if (component == 1) {return [self.cityArray count];} else {return [self.areaArray count] ;}
}

可以参考Uitableview的行和列,差不多的

非必要实现的方法

//展示的信息,可以是NSSTring,也可以是UIview
//- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
//    return @"chabuduo";
//}
//

//pickerview滑动函数

  • (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

简单常用的上面两个,还有很多其他的代理方法,可以参考UItableview;

UIPickerView 的代理方法用于处理用户的选择操作、自定义选项的外观以及其他与 UIPickerView 相关的事件。以下是一些常用的 UIPickerViewDelegate 和 UIPickerViewDataSource 协议中的代理方法:
UIPickerViewDelegate 协议中的代理方法:
pickerView(:didSelectRow:inComponent:):
当用户选择了 UIPickerView 中的某一行时调用该方法。你可以在该方法中获取选择的行和列索引,并根据需要进行相应的处理。
pickerView(
:viewForRow:forComponent:reusing:):
返回自定义 UIView 对象作为指定行和列的内容视图。你可以使用此方法自定义选项的外观,例如改变文本颜色、字体等。
pickerView(:rowHeightForComponent:):
返回指定列的行高。你可以使用此方法设置特定列的行高,以使选项在 UIPickerView 中正确显示。
UIPickerViewDataSource 协议中的代理方法:
numberOfComponents(in:):
返回 UIPickerView 中的列数(组件数)。你需要在此方法中指定需要显示的列数。
pickerView(
:numberOfRowsInComponent:):
返回指定列中的行数。你需要在此方法中指定每个列的行数,以确定每列将显示多少选项。

demo用到的其他函数

- (void)loadData {self.provinceArray = [[NSMutableArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"area.plist" ofType:nil]] ;self.cityArray = [[self.provinceArray objectAtIndex:0] objectForKey:@"cities"] ;self.areaArray = [[self.cityArray objectAtIndex:0] objectForKey:@"areas"] ;
}
- (UIView*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {UILabel* myview = nil ;myview = [[UILabel alloc] init] ;myview.textAlignment = NSTextAlignmentCenter ;myview.font = [UIFont systemFontOfSize:22] ;if (component == 0) {myview.text = [[self.provinceArray objectAtIndex:row] objectForKey:@"state"] ;} else if (component == 1) {myview.text = [[self.cityArray objectAtIndex:row] objectForKey:@"city"] ;} else {myview.text = [self.areaArray objectAtIndex:row] ;}return myview ;
}
//pickerview滑动函数
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {if (component == 0) {self.cityArray = [[self.provinceArray objectAtIndex:row] objectForKey:@"cities"] ;[self.pickerview reloadComponent:1] ;//调整各组所选的对象[self.pickerview selectRow:0 inComponent:1 animated:YES] ;if ([self.cityArray count] != 0) {self.areaArray = [[self.cityArray objectAtIndex:0] objectForKey:@"areas"] ;[self.pickerview reloadComponent:2] ;[self.pickerview selectRow:0 inComponent:2 animated:YES] ;}} else if (component == 1) {if ([self.cityArray count] != 0) {self.areaArray = [[self.cityArray objectAtIndex:row] objectForKey:@"areas"] ;[self.pickerview reloadComponent:2] ;[self.pickerview selectRow:0 inComponent:2 animated:YES] ;}} else {}
}

提示

其他没啥好说的了,因为用起来真的太像UItableview了,这里简单解释一下滑动函数的逻辑,如果滑动“省”,则更新市和区的component并其row归零;如果滑动“市”,则更新区的component并归零 ;

效果展示

在这里插入图片描述

http://www.hkea.cn/news/27862/

相关文章:

  • 数据库修改网站管理员密码seo网站有优化培训吗
  • 福田做商城网站建设找哪家公司好抖音怎么运营和引流
  • 厘米售卡站怎么做网站禁止搜索引擎收录的方法
  • 网站首页滚动图片怎么做谷歌搜索关键词排名
  • 嵩县网站开发友情链接获取的途径有哪些
  • 国家企业信息公示网(广东)海南快速seo排名优化
  • 高端网站设计 上海徐州seo排名公司
  • 泰安网站建设公司排名石家庄最新消息
  • 域名只做邮箱没网站要备案吗常见的网络推广方式包括
  • 昆山建设局网站360搜索首页
  • 正常做网站多少钱无锡网站制作无锡做网站
  • php做网站csdn网站seo公司哪家好
  • 今日头条建站工具何鹏seo
  • wordpress 培训模板优化落实疫情防控新十条
  • 关于做外汇现货的网站太原整站优化排名外包
  • 星悦做任务网站是新网站百度收录
  • 十大营销网站seo关键词查询工具
  • 怎么查询网站所有关键词靠谱的广告联盟
  • 超酷的网站设计磁力搜索引擎
  • 网站建设写程序用什么软件成都疫情最新消息
  • 做网站需要什么资金2022今天刚刚发生地震了
  • 建设网站费用主要包括哪些google商店
  • 专注邯郸建设手机网站贴吧友情链接在哪
  • 网站备案拍照背景志鸿优化网官网
  • 网站百度知道怎么做推广网站搜索引擎优化的方法
  • 网站建设注意哪些问题sem和seo是什么职业岗位
  • 一_建设网站前的市场分析奶茶软文案例300字
  • 做网站智能工具江阴企业网站制作
  • 怎么看网站有没有做推广大数据营销系统多少钱
  • 广东工厂搜索seoseo平台优化服务