#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. notes

    http://www.cnblogs.com/titicia/p/4388318.html http://blog.csdn.net/kanosword/article/details/5258679 ...

  2. 【Hibernate框架】关联映射(多对多关联映射)

    按着我们的总结行进计划,接下来,就是有关于多对多映射的总结了. 我们来举个例子啊,很长时间以来,房价暴涨不落,但是还有很多人拥有很多套房产,假如说,一个富豪拥有九套房产,家里人么准去住哪一套,我们就以 ...

  3. MIT 6.828 JOS学习笔记17. Lab 3.1 Part A User Environments

    Introduction 在这个实验中,我们将实现操作系统的一些基本功能,来实现用户环境下的进程的正常运行.你将会加强JOS内核的功能,为它增添一些重要的数据结构,用来记录用户进程环境的一些信息:创建 ...

  4. mysql优化

    一.优化事项 1. 数据库(表)设计合理    (不合理设计导致内伤)    我们的表设计要符合3NF   3范式(规范的模式) , 有时我们需要适当的逆范式.2. sql语句的优化(索引,常用小技巧 ...

  5. Linux SHELL 命令入门题目(一)

    新年新气象,注重知识积累,提高手敲代码能力,而不是眼高手低,只会复制黏贴. 1.使用shell 打印 “Hello World!” 2.求变量'hello world'的字符长度 3.$0 .$SHE ...

  6. Linux 用户添加sudo 权限

    编辑/etc/sudoers 搜索root 添加 账号 ALL=(ALL) ALL

  7. jQuery技巧

    回到顶部按钮 图片预加载 判断图片是否加载完 自动修补破损图像 Hover切换class类 禁用输入 停止正在加载的链接 toggle fade/slide 简单的手风琴 使两个DIV同等高度 在浏览 ...

  8. Python开发工具PyCharm个性化设置(图解)

    Python开发工具PyCharm个性化设置,包括设置默认PyCharm解析器.设置缩进符为制表符.设置IDE皮肤主题等,大家参考使用吧. JetBrains PyCharm Pro 4.5.3 中文 ...

  9. C到C++的升级

    const 在C中只是个“只读变量”,并不是真正意义上的常量,通过指针能改变它,如下 #include<stdio.h> int main() { ;//声明只读变量a为0 int* p= ...

  10. 使用docker toolbox 在windows上搭建统一环境

    1.先下载docker toolbox 以下是下载地址: http://get.daocloud.io/#install-docker-for-mac-windows 2.下载安装 git windo ...