iOS-UI-tabelView
来源:互联网 发布:html js 视频教程下载 编辑:程序博客网 时间:2024/05/18 01:58
// ViewController.m
// UI-tabelView
//
// Created by jzq_mac on 15/7/30.
// Copyright (c) 2015年 jzq_mac. All rights reserved.
//
#import "ViewController.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT CGRectGetHeight(self.view.frame)
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
NSArray *list;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
list = @[@"我..........",@"是...",@"一..",@"个",@"好",@"人",@"你",@"信",@"不",@"信",@"我",@"嘛",@"我",@"是",@"一",@"个",@"好",@"人",@"你",@"信",@"不",@"信"];
// UITableView使用的是重用机制(滚筒原理)通过重TabelView的 cell 达到节省内存的目的,使用一个字符串类型的ID判断是那种cell
// ****UITableView有两个必须实现的代理方法在datasourceDelegate
// UITableView 是UIscrollView的子类,其所有方法属性皆可以用
// UITableView有两种样式一种是平铺,一种是分组
UITableView *myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, WIDTH, HEIGHT-20) style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;
[self.view addSubview:myTableView];
// 在需要更新数据的时候可以使用reloadData 来更新数据;当咱们使用reloadData的时候所有大力方法都会重新调用一次,用来更新数据
// UITableView 用的对象去调用 reloadData
// [myTableView reloadData];
}
//在这个组里面有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section{
// Section表示第几组,从0开始
return list.count;
}
//显示的内容UITableView;UITableView上的每一个横格都是一个UITableViewCell
//UITableView 上面的数据 就是显示在 每一个UITableViewCell上
//cellForRowAtIndexPath 有多少行就会调用多少次
//原因:他的返回值是UITableViewCell需要提供给UITableView他需要数量的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// cellID的唯一标识
NSString *cellID = @"cityCell";
// UITableView重用机制是通过查找cell的唯一标识cellID来判断这个cell对象是否存在,如果不存在,就去实例化
//通过cellID来查找UITableView的cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
// 如果没有查找到可以重用的cell就实列化cell对象
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
// 不要在初始化cell的地方去显示数据,否则数据会混乱
}
// 显示数据的时候,写在初始化的外面
// 不能在这个方法里面去加载数据,因为这个方法会不断的调用
// 可以通过indexPath得到是哪一组(indexPath.section),也可以得到是哪一行(indexPath.row)都是从0开始
cell.textLabel.text = list[indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"2.jpg"];
return cell;
}
//选择cell的时候调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",list[indexPath.row]);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- iOS-UI-tabelView
- IOS UI 之 去tabelView分割线
- IOS 横向TabelView
- iOS——TabelView
- IOS开发——TabelView下拉刷新
- iOS 的tabelView 重用机制 缓存池
- 【iOS开发TableView】TabelView自定义cell
- 关于iOS tabelView隐藏多余的cell
- iOS tabelView获取当前选中cell
- 【11/04】 iOS开发成长之路,【tabelView cell复用】
- ios的tabelView滚动最后一行(常用于聊天软件)
- 渣蜀黍 - iOS 个人笔记(三)_上拉下拉的tabelview
- iOS tabelView 分割线从最左边开始及隐藏多余的cell
- ios UI
- ios UI
- iOS UI
- 【.h】tabelview 部分内容
- 通讯录 CoreData & tabelView
- 用Spring将Service注入到Servlet中
- hdu1420
- [LeetCode] Word Search
- CBitmap转换成GDI+的Bitmap (Image)
- PAAS平台对比:OpenShift VS CloudFoundry【51CTO调研报告】
- iOS-UI-tabelView
- 如何在eclipse中导入两个相同的工程
- 转载_蓝牙协议栈架构
- jQuery只网站品牌列表的效果
- SGU167
- hdu4506 小明系列故事——师兄帮帮忙 解题报告
- 29. JavaScript - 测试 jQuery
- (一)JM代码学习笔记一NAL单元的相关代码
- 数据请求之前判断是否有网