为什么80%的码农都做不了架构师?>>>   

UITableView是iOS中最常用的控件了,所以使用起来也很简单。

ViewContoller.h 文件 (继承UITableViewDelegate&UITableViewDataSource协议):

//
//  ViewController.h
//  ViewController
//
//  Created by monkey mot on 13-6-20.
//  Copyright (c) 2013年 monkey mot. All rights reserved.
//#import <UIKit/UIKit.h>@interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *mytable;
@end

ViewController.m 实现协议来呈现tableView :

//
//  ViewController.m
//  ViewController
//
//  Created by monkey mot on 13-6-20.
//  Copyright (c) 2013年 monkey mot. All rights reserved.
//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad
{[super viewDidLoad];self.view.backgroundColor = [UIColor blackColor];self.mytable =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];self.mytable.delegate = self;self.mytable.dataSource = self;//self.mytable.backgroundColor = [UIColor grayColor];[self.view addSubview:self.mytable];// Do any additional setup after loading the view, typically from a nib.
}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{return 5;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return 5000;
}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{UITableViewCell *result = nil;if( [tableView isEqual:self.mytable]) {static NSString *cellIdentifier = @"Cells";result = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];if( result == nil) {result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];}result.textLabel.text = [NSString stringWithFormat:@"Section %ld Cell %ld",(long)indexPath.section , (long)indexPath.row];}return result;
}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{if( [tableView isEqual:self.mytable] == NO)return ;[[tableView cellForRowAtIndexPath:indexPath] setBackgroundColor: [UIColor redColor]];UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"cell is selected"message: [NSString stringWithFormat:@"cell is %ld",(long)indexPath.row]delegate: nilcancelButtonTitle: @"close"otherButtonTitles: nil];[alert show];
}-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{if( [tableView isEqual:self.mytable]) {return @"This is my table section";}return @"";
}@end

run一下 会出现table 跟 cell 点击相应的cell 能触发事件

转载于:https://my.oschina.net/imot/blog/139052

在iOS中使用tableView相关推荐

  1. iOS中的截屏(屏幕截屏及scrollView或tableView的全部截屏)

    iOS中的截屏(屏幕截屏及scrollView或tableView的全部截屏) 2017.03.16 12:18* 字数 52 阅读 563评论 4喜欢 2 1. 截取屏幕尺寸大小的图片并保存至相册 ...

  2. ios中关于delegate(委托)的使用心得

    ios中关于delegate(委托)的使用心得 分类: iOS开发2012-05-15 10:54 34793人阅读 评论(9) 收藏 举报 iosuiviewtimerinterfaceprinti ...

  3. iOS中持久化存储SQLite(一)

    在iOS中做持久化存储有多种方案,其中包括plist, preference, sqlite, core data,其中: (1)plist, preference适合小型数据存储,因为每次存储前都必 ...

  4. iOS 中的 xml 解析

    在ios 中解析xml 的方法有很多种 1.苹果原生 NSXMLParser:SAX方式解析,使用简单 2.第三方框架 libxml2:纯c语言,默认包含在ios  sdk中,同时支持DOM 和 SA ...

  5. iOS中常见的设计模式(MVC/单例/委托/观察者)

    关于设计模式这个问题,在网上也找过一些资料,下面是我自己总结的,分享给大家 如果你刚接触设计模式,我们有好消息告诉你!首先,多亏了Cocoa的构建方式,你已经使用了许多的设计模式以及被鼓励的最佳实践. ...

  6. ios tableview_iOS简单TableView示例教程

    ios tableview In this tutorial we're going to discuss and implement the TableView UI element in our ...

  7. 浅谈iOS中关于app的优化

    目录 我要给出的建议将分为三个不同的等级: 入门级. 中级和进阶级: 入门级(这是些你一定会经常用在你app开发中的建议) 1. 用ARC管理内存 2. 在正确的地方使用reuseIdentifier ...

  8. ios html格式转换,如何使用HTML模版和iOS中的UIPrintPageRenderer来生成PDF文档

    如何使用HTML模版和iOS中的UIPrintPageRenderer来生成PDF文档 作者:GABRIEL THEODOROPOULOS,时间:2016/7/10 翻译:BigNerdCoding, ...

  9. [置顶] iOS中 支付宝钱包详解/第三方支付

    [置顶] iOS中 支付宝钱包详解/第三方支付 韩俊强的博客 每日更新关注:http://weibo.com/hanjunqiang  新浪微博! 一.在app中成功完成支付宝支付的过程 1.申请支付 ...

最新文章

  1. 通俗说基于Yarn的Map-Reduce过程
  2. linux下面把png文件转化为背景透明
  3. 频频霸榜的 Python,竟遭开发者嫌弃!
  4. 5.微服务:从设计到部署 --- 事件驱动数据管理
  5. 中英文翻译、语料库等资料
  6. 苍井空是如何勾搭上社交电商的? - 案例 - i黑马网
  7. Oracle体系结构图(思维导图及详解)
  8. 苹果id被禁用_【苹果ios游戏推荐】模拟人生免费版
  9. linux+时间戳+ns,时间戳转换工具
  10. 遥感图像裁剪后在ENVI里显示为黑色解决办法
  11. linux dns配置服务器报告,Linux DNS服务实验报告
  12. 如何破解有密码的PDF文档(无需下载破解软件)
  13. 桌面计算机图标无法显示属性,Win7系统桌面图标显示异常的解决方法大全
  14. aes ccm模式 java_AES_GCM和AES_CCM的选择
  15. 计算机课拔线头检讨书,乱接电线检讨书
  16. mysql实现俩个属性加减运算_mysql加减乘除
  17. 图像绘制到屏幕上的原理。
  18. 蒙特卡罗方法(一):1.蒲丰投针求pi、2.掷骰子--求连续掷两颗骰子,点数之和大于6且第一次掷出的点数大于第二次掷出点数的概率
  19. 泰雷兹推出未来飞机的大脑PureFlyt
  20. SpringBoot使用tkmapper

热门文章

  1. JDK1.8源码(三)——java.lang.String 类
  2. 分布式缓存技术memcached学习(一)——linux环境下编译memcahed
  3. 配置 L2 Population - 每天5分钟玩转 OpenStack(114)
  4. JAVA 代码里中文乱码问题
  5. ZTE-中兴捧月-北京线下测试赛--B题
  6. mysql中count的用法
  7. 桌面倒计时2.0 涉及知识点详解及源码分享
  8. 解决jQuery和其它库的冲突
  9. iphone XCode调试技巧之EXC_BAD_ACCESS中BUG解决
  10. multiplexed pins