UITableView(一)
#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(一)的更多相关文章
- iOS UITableView 与 UITableViewController
很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...
- UITableView(二)
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- iOS: 在UIViewController 中添加Static UITableView
如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...
- iOS 编辑UITableView(根据iOS编程编写)
上个项目我们完成了 JXHomepwner 简单的应用展示,项目地址.本节我们需要在上节项目基础上,增加一些响应用户操作.包括添加,删除和移动表格. 编辑模式 UITableView 有一个名为 e ...
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
- UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题
UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...
- UITableview delegate dataSource调用探究
UITableview是大家常用的UIKit组件之一,使用中我们最常遇到的就是对delegate和dataSource这两个委托的使用.我们大多数人可能知道当reloadData这个方法被调用时,de ...
- UITableView点击每个Cell,Cell的子内容的收放
关于点击TableviewCell的子内容收放问题,拿到它的第一个思路就是, 方法一: 运用UITableview本身的代理来处理相应的展开收起: 1.代理:- (void)tableView:(UI ...
- 使用UITableView的分组样式
分组样式顾名思义是对TableView中的数据行进行分组处理,每个分组都有一个header和footer. TableView中header的英文文本是大写的,footer的英文文本是小写的.如下图浅 ...
随机推荐
- 剑指Offer-【面试题05:从头到尾打印链表】
package com.cxz.question5; import java.util.Stack; /* * 输入个链表的头结点,从尾到头反过来打印出每个结点的值. * */ public clas ...
- Javascript、Jquery获取浏览器和屏幕各种高度宽度
Javascript: IE中:document.body.clientWidth ==> BODY对象宽度document.body.clientHeight ==> BODY对象高度d ...
- ng1.3+表单验证<AngularJs>
前一篇文章说过,ng1.3+以后对于表单验证有了优化,它不再需要一个详细的表达式状态创建元素显示或隐藏. 例如:我们在ng1.3之前的版本都需要如下写法: <div class="er ...
- 六个漂亮的 ES6 技巧
六个漂亮的 ES6 技巧 转载 原文:2ality 译文:众成翻译 链接:http://www.zcfy.cc/article/346 在这篇文章里,我将演示 6 种 ES6 新特性的使用技巧.在每个 ...
- hellocharts包的使用心得
首先将jar包导入Libs里面然后add进入于activity中调用 xml中加入布局 <lecho.lib.hellocharts.view.LineChartView android:id= ...
- 【vuejs小项目——vuejs2.0版本】组件化的开发方式
对于多张页面需要里存在相同模块,可以进行组建化的开发模式. 例如:此处需要一个评分标准组件,创建一个components/star/star.vue. 在需要引入该组建的页面上 import进去< ...
- java 随机生成身份证代码
import java.util.Calendar; import java.util.Collection; import java.util.HashMap; import java.util.I ...
- 用Barcode生成条形码图片
使用第三方类库:BarcodeLib.dll private BitmapImage GenerateBarcodeBitmap(string visitId) { BarcodeLib.Barcod ...
- CentOS 7.x设置自定义开机启动,添加自定义系统服务
Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: /l ...
- bootstrap之CDN
bootstrap之CDN CDN是Content Delivery Network的缩写,简单的说就是Bootstrap把自己的css.Js等文件托管到某一个网络服务器上使用时调用.如果与Inter ...