#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. CSS清除浮动技巧

    一般浮动是什么情况呢?一般是一个盒子里使用了CSS float浮动属性,导致父级对象盒子不能被撑开,这样CSS float浮动就产生了. 本来两个黑色对象盒子是在红色盒子内,因为对两个黑色盒子使用了f ...

  2. SQL Server 事务以及事务日志综述

    事务是一个非常重要的概念,特此在这里写一些文章来总结.整篇文章还在持续更新中. 在本系列文章中,你将看到以下内容: 数据库事务(Database Transaction)概述 事务操作(BEGIN/C ...

  3. SQL语句实现Split并合并查询结果

    需求是这样的,需要将数据库中的支付方式列(用";"分割的字符串)按支付方式拆分: 首先参考博客园split的文章,我采用方法2, IF EXISTS ( SELECT * FROM ...

  4. 3.4.4 数据预留和对齐(skb_reserve, skb_push, skb_put, skb_pull)

    转自:http://book.51cto.com/art/201206/345043.htm <Linux内核源码剖析:TCP/IP实现>本书详细论述了Linux内核2.6.20版本中TC ...

  5. pyqt的信号槽机制(转)

    PySide/PyQt Tutorial: Creating Your Own Signals and Slots This article is part 5 of 8 in the series  ...

  6. Mac下搭建php开发环境[翻译]+自己总结(红字)

    原英文链接:http://www.codeweblog.com/mac-os-x-to-configure-apache-php-mysql/ Mac OS X 内置了Apache 和 PHP,这样使 ...

  7. mysql 数据库可以非本地访问

      GRANT ALL PRIVILEGES ON 数据库名.* TO root@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;

  8. make工作时的执行步骤

    GNU的make工作时的执行步骤 (1)读入所有的Makefile (2)读入被include的其它Makefile (3)初始化文件中的变量 (4)推导隐晦规则,并分析所有的规则 (5)为所有的目标 ...

  9. 闭包和重写函数 返回IE浏览器版本号

    开发过程中我们有时候需要知道IE的版本号,我们知道得到IE的版本号的方法: var v = 3, div = document.createElement('div'), all = div.getE ...

  10. JavaScript解惑记之Array.prototype.sort()

    前言 看JS红宝书的5.2.5章节关于sort()方法,如何用一个compare函数,让数组顺序,倒序,有点云里雾里的.在网上度娘了一下,发现更迷糊了.走投无路的情况下,只能发动神技能,去 stack ...