iOS探索--TableView的使用
来源:互联网 发布:软件测试课程大纲 编辑:程序博客网 时间:2024/05/24 05:32
一、简介
UITableViewStylePlain和UITableViewStyleGrouped。这两者操作起来其实并没有本质区别,只是后者按分组样式显示前者按照普通样式显示而已。大家先看一下两者的应用:
二、代码示例
1.TableViewController.xib
配置TableView,选择View下面的TableView鼠标右键,看到dataSource和delegata,按着confrol分别拖动到dataSource到File’s Owner进行关联,关联后就如上图所示。
2.TableViewController.h
#import <UIKit/UIKit.h>@interface TableViewController : UIViewController<UITabBarDelegate,UITableViewDataSource>@property(nonatomic,retain)NSArray* list;@end
3.TableViewController.m
#import "TableViewController.h"@interface TableViewController (){ __weak IBOutlet UIButton *BackButton;}@end@implementation TableViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSArray *array=[[NSArray alloc]initWithObjects:@"c",@"java",@"c++",@"oc",@"Python",@"go",@"c#",@"js",@"javaweb",@"asp.net", nil]; self.list = array;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}-(IBAction)back:(id)sender{ [self dismissViewControllerAnimated:YES completion:nil];}-(void)viewDidUnload{ [super viewDidLoad]; self.list=nil;}//返回总行数-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.list count];}//为每一行赋值static NSString *SimpleTableIdentifier=@"SimpleTableIdentifier";-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; if(cell==nil){//如果行元素为空的话 则新建一行 cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier]; } //取得当前行 NSUInteger row=[indexPath row]; //设置每一行要显示的值 cell.textLabel.text=[_list objectAtIndex:row]; return cell;}//设置点击事件-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //该方法响应列表中行的点击事件 NSString *heroSelected=[_list objectAtIndex:indexPath.row]; //indexPath.row得到选中的行号,提取出在数组中的内容。 UIAlertView *myAlertView = [[UIAlertView alloc]initWithTitle:@"语言" message:heroSelected delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [myAlertView show]; //点击后弹出该对话框。}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
然后运行。运行结果如第一张图。
阅读全文
1 0
- iOS探索--TableView的使用
- ios tableView 的使用
- iOS--TableView的简单使用
- iOS TableView的基本使用
- ios的tableView使用详解
- iOS tableView的Cell的使用方式
- iOS 使用两个tableview的瀑布流
- iOS开发笔记--TableView的详细使用
- iOS 中tableview的使用
- 【IOS】 TableView and sectionIndex 的使用
- iOS中tableview的使用(1)
- iOS开发表格TableView的使用
- iOS开发笔记--TableView的详细使用
- iOS TableView 使用(swift)
- iOS TableView 使用详解
- IOS:tableview的重用
- iOS---tableView的代理
- ios:TableView的用法
- java编码规范
- Asp .Net Core 2.0 登录授权以及多用户登录
- OkHttp封装
- 性能较好的JVM参数配置
- fatal: Authentication failed could not read from remote repository
- iOS探索--TableView的使用
- 深度网络的基础组件
- bdlink创建、使用、删除
- ATL与COM之间的关系、ATL的特点与基本使用方法
- iOS 时间与日期处理
- Codeforces Round #430 (Div. 2)
- Spring Cloud中,Feign常见问题总结
- python提交表单和提交json
- android studio 常用配置