#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

    @property (nonatomic, retain) NSArray *_dataList;
@property (nonatomic, retain) UITableView *_myTableView; @end
//
// ViewController.m
// ios13
//
// Created by fredric on 16/4/14.
// Copyright © 2016年 fredric. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; NSArray *list = [NSArray arrayWithObjects:@"条目1",@"条目2", nil];
self._dataList = list; UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.dataSource = self;
tableView.delegate = self; self._myTableView = tableView; [self.view addSubview:self._myTableView]; } #pragma mark - Table view data source
/*-
* 创建某个section及某个row中UITableViewCell的定义
* NSIndexPath 包含sectoin、row两个方法获取对应的section和row
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //通过Identifier在tableView的缓冲池中寻找cell对象
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if(cell == nil){
//若缓冲池中没有则创建这个对象
// UITableViewCell 包含四种显示方式
// UITableViewCellStyleDefault 为默认的左对齐格式
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
} cell.textLabel.text = [self._dataList objectAtIndex:[indexPath row]];
cell.detailTextLabel.text = @"详细信息"; return cell;
} //一共有多少个分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} //分区中有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self._dataList count];
} #pragma mark - Table view delegate
//选择UITableView的某一行
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *showSelection;
showSelection = [[UIAlertView alloc]
initWithTitle: @"已经选择了"
message: [NSString stringWithFormat: @"%d", [indexPath row]]
delegate: nil
cancelButtonTitle: @"Ok"
otherButtonTitles: nil];
[showSelection show];
} @end

UITableView(一)的更多相关文章

  1. iOS UITableView 与 UITableViewController

    很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...

  2. UITableView(二)

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  3. iOS: 在UIViewController 中添加Static UITableView

    如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...

  4. iOS 编辑UITableView(根据iOS编程编写)

    上个项目我们完成了 JXHomepwner 简单的应用展示,项目地址.本节我们需要在上节项目基础上,增加一些响应用户操作.包括添加,删除和移动表格. 编辑模式 UITableView 有一个名为  e ...

  5. 使用Autolayout实现UITableView的Cell动态布局和高度动态改变

    本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...

  6. iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法

    "UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...

  7. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  8. UITableview delegate dataSource调用探究

    UITableview是大家常用的UIKit组件之一,使用中我们最常遇到的就是对delegate和dataSource这两个委托的使用.我们大多数人可能知道当reloadData这个方法被调用时,de ...

  9. UITableView点击每个Cell,Cell的子内容的收放

    关于点击TableviewCell的子内容收放问题,拿到它的第一个思路就是, 方法一: 运用UITableview本身的代理来处理相应的展开收起: 1.代理:- (void)tableView:(UI ...

  10. 使用UITableView的分组样式

    分组样式顾名思义是对TableView中的数据行进行分组处理,每个分组都有一个header和footer. TableView中header的英文文本是大写的,footer的英文文本是小写的.如下图浅 ...

随机推荐

  1. 动态创建 Lambda 表达式

    首先我们看一个简单 Lambda 表达式的构成. i => i > 5 在这个表达式中,"i" 被称为 Parameter,"i > 5" 是 ...

  2. SSH ProxyCommand

    简单的说就是SSH层面的代理服务器,实现通过跳板机执行SSH相关命令到目标机器的代理服务.

  3. Quartz定时调度框架

    Quartz定时调度框架CronTrigger时间配置格式说明 CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年 ...

  4. 【MySQL】 查询某个数据库有多少张数据表

    SELECT COUNT(*) TABLES, table_schema FROM information_schema.TABLES WHERE table_schema = 'performanc ...

  5. python学习6 web开发

    wsgi自带,用语构建简单服务器 例子 from wsgiref.simple_server import make_server def index(env, res): res('200 ok', ...

  6. 在公司里面,如何让笔记本连上wifi?

    1.复制谷歌浏览器图标的快捷方式,重命名为chrome Android,鼠标右键设置该快捷方式的属性,在目标处,加上 C:\Users\admin\AppData\Local\Google\Chrom ...

  7. 机器学习之K-近邻算法

    机器学习可分为监督学习和无监督学习.有监督学习就是有具体的分类信息,比如用来判定输入的是输入[a,b,c]中的一类:无监督学习就是不清楚最后的分类情况,也不会给目标值. K-近邻算法属于一种监督学习分 ...

  8. java 判断两个list是否相等

    /** * 队列比较 * @param <T> * @param a * @param b * @return */ public static <T extends Compara ...

  9. [资料分享]nutch视频教程

  10. 【原】iOS学习之NSDate在项目中的一些类目扩展

    在项目中,我们可能会面对各种各样的对于时间的需求,在这里提供几种可能会用到的需求代码 1.与今天的时间做比较,返回日期差值 代码: - (NSInteger)compareWithToday { NS ...