iOS学习笔记-028.UITableView的省市主从表
来源:互联网 发布:linux系统当前版本 编辑:程序博客网 时间:2024/06/06 02:41
- UITableView的省市主从表
- 一主从表的创建
- 二push界面NavigatioonController
- 三代码
- MainUITableViewControllerm
- CityUITableViewControllerm
- 三图示
UITableView的省市主从表
一、主从表的创建
- 选择 TableView Controller。
- 拖动到storyboard中。
- 设置cell的标示符(Identifier),这个必须要注意,代码中使用的标示符,和这个一样。
- 创建我们需要的控制器,继承自 UITableViewController
- 给我们在 3 中创建的UITableViewController 界面,设置它的控制器
- 如果需要指定那个界面为第一个界面,请选中 属性 设置中的 “Is Initial VIew Controller”
- 在对应的控制器内完成操作。
二、push界面(NavigatioonController)
我们想通过push 这种来推出新的控制器,那么我们需要使用 NavigationController
1. 选择 Navigation Controller。
2. 拖动到storyboard中。
3. 指定为第一个界面,选中 属性 设置中的 “Is Initial VIew Controller”
4. 连线到需要的界面中
5. 加载和设置其他界面
注意:我们在使员工push方式的时候, 第二个界面要按”返回“回到 第一个界面,那么这个“返回”要设置到第一个的返回按钮中。
如:从“省份列表”—–>”城市列表”
三、代码
1. MainUITableViewController.m
//// MainUITableViewController.m// 03_UIView20_UITableView5_主从表//// Created by 杞文明 on 16/1/3.// Copyright © 2016年 杞文明. All rights reserved.//#import "MainUITableViewController.h"#import "CityUITableViewController.h"@interface MainUITableViewController(){ NSMutableArray * _provinceListM; NSMutableDictionary * _citiesDicM;}@end@implementation MainUITableViewController/**加载*/- (void)viewDidLoad{ [super viewDidLoad]; //1.加载省数据 _provinceListM = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"provinces.plist" ofType:nil]]; //2.加载市数据 _citiesDicM = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cities.plist" ofType:nil]];}/**行数*/-(NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _provinceListM.count;}/**每个单元格*/-(UITableViewCell*)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{ static NSString* identifier = @"myCell"; UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if(cell==nil){ cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } [cell.textLabel setText:_provinceListM[indexPath.row]]; return cell;}/**目标从之气调用之前*/-(void)prepareForSegue:(nonnull UIStoryboardSegue *)segue sender:(nullable id)sender{ //1.获取选中的省数据 NSString * provinceStr = _provinceListM[self.tableView.indexPathForSelectedRow.row]; //2.获取选中的省对应的市数据 NSArray* citiesList = _citiesDicM[provinceStr]; //3.获取目标控制器 CityUITableViewController* desCon = segue.destinationViewController; //4.把市数据传递给目标控制器 [desCon setCitiesList:citiesList]; [desCon setProvinceName:provinceStr];}//- (void)tableView:(nonnull UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{// NSLog(@"选中的是----"+)// [self dismissViewControllerAnimated:YES completion:nil];//}@end
2. CityUITableViewController.m
//// CityUITableViewController.m// 03_UIView20_UITableView5_主从表//// Created by 杞文明 on 16/1/3.// Copyright © 2016年 杞文明. All rights reserved.//#import "CityUITableViewController.h"@implementation CityUITableViewController/**总的行数*/-(NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _citiesList.count;}/**返回每个单元格*/-(UITableViewCell*)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{ static NSString * identifier = @"myCityCell"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell==nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } [cell.textLabel setText:_citiesList[indexPath.row]]; return cell;}/**选中*/-(void)tableView:(nonnull UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{ NSString * cityName = _citiesList[indexPath.row]; NSLog(@"%@--%@",_provinceName,cityName); [self performSelector:@selector(dismissMy) withObject:self afterDelay:1];}/**关闭*/-(void)dismissMy{// [self dismissViewControllerAnimated:YES completion:nil]; [self.navigationController popViewControllerAnimated:YES];}@end
三、图示
0 0
- iOS学习笔记-028.UITableView的省市主从表
- IOS UITableView 学习笔记
- iOS 学习笔记 uitableView
- IOS学习笔记-UITableView表索引的颜色设置
- iOS学习笔记8-UITableView的定制
- xamarin学习笔记B07(ios的UITableView)
- iOS开发学习笔记 UITableview
- 转发iOS UITableView学习笔记
- iOS学习笔记03-UITableView
- IOS学习笔记(十一)之IOS开发之表视图(UITableView)的基本介绍(一)
- IOS学习笔记(十一)之IOS开发之表视图(UITableView)的基本介绍(一)
- IOS学习笔记(十二)之IOS开发之表视图(UITableView)的讲解与使用(二)
- IOS学习笔记(十一)之IOS开发之表视图(UITableView)的基本介绍(一)
- 方法定制iOS学习笔记8-UITableView的定制
- iOS学习笔记—— UItableView 控件的简单使用
- iOS学习笔记:UITableView想要的都有
- iOS学习笔记-026.UITableView的基本用法
- iOS学习笔记-029.UITableView的编辑模式
- AndFix热修复 —— 实战与源码解析
- 使用nodemon让node自动重启
- Docker 学习笔记(2)-基础用法
- https/http 413 416 错误
- C#图像图片扭曲,透视变换
- iOS学习笔记-028.UITableView的省市主从表
- How to spread receivers over worker hosts in Spark streaming - draft
- Android studio中使用SVN进行代码管理——文件忽略
- FATFS 简单示例
- Android苦手的App之旅(2)
- Android 4.4之后状态栏和导航栏细节美化(沉浸式状态栏)
- jsp中的JSTL与EL表达式用法
- Xcode7及以上版本中使用后http请求
- [厉害了Word哥]这些API接口,随便拿出来一个就能装逼、赚钱