iOS:实现表格填充和选择操作
功能:创建一个列表,用数组填充表格,并支持选择列表行
//
// main.m
// Hello
//
// Created by lishujun on 14-8-28.
// Copyright (c) 2014年 lishujun. All rights reserved.
// #import <UIKit/UIKit.h> // 视图控制器对象
@interface HelloWorldViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
NSArray *array;
UITableView *tableView;
//不用@property声明,就不能用self进行引用? 有什么差异,我得弄清楚
}
@end @implementation HelloWorldViewController -(HelloWorldViewController *) init
{
array = [[NSArray alloc]initWithObjects:@"oops", @"hello", @"world", nil];
return self;
} -(void) loadView
{
// 创建视图对象
UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor lightGrayColor];
self.view = contentView; // 创建tableView
tableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[tableView setDataSource:self];
[tableView setDelegate:self]; // tableView加入到内容视图
[contentView addSubview:tableView];
} // --------DataSource接口必须实现的方法,用于填充表格-----------
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return ; //设定列表分区个数
} -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count]; //设定列表长度
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 生成列表单元(尽可能复用已有单元)
static NSString *simpleTableIdentifer = @"SimpleTableIdentifer"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifer];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifer];
}
cell.textLabel.text = array[indexPath.row];
return cell;
} // ----------实现Delegate接口的方法,用于操作--------------- -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 行选中之前的事件,下面代码实现是实现取消第一行的选择,即不允许选择
if(indexPath.row == )
{
return nil;
}
else
{
return indexPath;
}
} -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//行选中事件
NSString *rowValue = array[indexPath.row];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; //取消选中状态
NSLog(@"%@", rowValue); }
@end // 委托对象
@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
{
IBOutlet UIWindow *window;
} @property (nonatomic, retain) UIWindow *window;
@end @implementation HelloWorldAppDelegate
@synthesize window; -(void) applicationDidFinishLaunching:(UIApplication *)application
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
HelloWorldViewController *viewController = [[HelloWorldViewController alloc]init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
} @end // 程序入口
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
}
}
iOS:实现表格填充和选择操作的更多相关文章
- 通过对表格数据的选择对input的value进行修改
通过对表格数据的选择对input的value进行修改 $(function(){ $("#tb_gys").datagrid({ url:'getGysinfoList.actio ...
- 基于MVC4+EasyUI的Web开发框架经验总结(14)--自动生成图标样式文件和图标的选择操作
在很多Web系统中,一般都可能提供一些图标的选择,方便配置按钮,菜单等界面元素的图标,从而是Web系统界面看起来更加美观和协调.但是在系统中一般内置的图标样式相对比较有限,而且硬编码写到样式表里面,这 ...
- Web自动化 - 选择操作元素 2
文章转自 白月黑羽教Python 前面我们看到了根据 id.class属性.tag名 选择元素. 如果我们要选择的 元素 没有id.class 属性, 这时候我们通常可以通过 CSS selector ...
- jQuery实现列表框双向选择操作
对列表框的操作经常碰到过这样的应用:从左侧的列表框中选中要选的项添加到右侧列表框中,然后提交最终选择的项,对误操作而选中的项还可以执行移除操作.在很多系统中应用比如说求职网站的选择意向工作地区,QQ好 ...
- selenium 显示等待wait.until 常用封装 及下拉框的选择操作等
from selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait a ...
- IOS 取消表格单元格 TableViewCell 去掉高亮状态 点击Cell取消选择状态
以下是两种实现效果 1. 自定义cell 继承UITableViewCell 重写 -(void)setSelected:(BOOL)selected animated:(BOOL)animated ...
- SSRS 实用技巧 ---- 为表格添加展开/折叠操作(明细报表)
相信很多人都会遇到这样的需求:当表格按照某几个列分组时,需要为组添加展开和折叠的操作. 最初展现表格的时候只展现最外层分组,然后点击展开后可以查看分组内的明细情况. 先来一张效果图,然后再看具体如何实 ...
- IOS自定义表格UITableViewCell
在UITableView中,自定义表格,最原始是继承UITableViewCell,然后通过写代码方式去搞,但是这个费事了. 1.在storyboard中 给一个ViewController的tabi ...
- ul、li模仿ios的TableView实现城市选择
最近项目一个接着一个,之前说的精创环的项目还没做完,今天说先把那个放一下,先做访客系统,销售会见客户之后可以对客户进行一个跟踪记录,原型图也给了,今日头条的频道自定义页面一样. 如果是在IOS上让我来 ...
随机推荐
- lucene索引并搜索mysql数据库[转]
由于对lucene比较感兴趣,本人在网上找了点资料,终于成功地用lucene对mysql数据库进行索引创建并成功搜索,先总结如下: 首先介绍一个jdbc工具类,用于得到Connection对象: im ...
- 以色列学生---debugger 构建
http://eli.thegreenplace.net/2011/01/23/how-debuggers-work-part-1 http://eli.thegreenplace.net/
- linux中的网络通信指令 分类: 学习笔记 linux ubuntu 2015-07-06 16:02 134人阅读 评论(0) 收藏
1.write write命令通信是一对一的通信,即两个人之间的通信,如上图. 效果图 用法:write <用户名> 2.wall wall指令可将信息发送给每位同意接收公众信息的终端机用 ...
- CentOS 6.7安装配置Ansible
1.准备CentOS环境 yum update && yum upgrade 2.控制服务器与被管理服务器要求 Master:Python 2.6+ Slave:Python 2.4+ ...
- 初建FreeMarker工程
初建FreeMarker工程 ——@梁WP 背景:听说freemarker可以用来写页面的组件,热衷于编写可重用代码的我,迫不及待地研究了freemarker,不过,在写组件之前,还是先研究一下fre ...
- POJ 1845 Sumdiv(因子分解+快速幂+二分求和)
题意:给你A,B,让求A^B所有的因子和模上9901 思路:A可以拆成素因子的乘积: A = p1^x1 * p2^x2 *...* pn^xn 那么A^B = p1^(B*x1) * p2^(B*x ...
- IE8下网页中的视频会遮挡住顶层DIV的解决办法
在IE8浏览器下,发现网页中的视频会遮挡住本来固定在最顶层的DIV.即便使用z-index也无法解决.但是其他浏览器是正常的. 解决的办法很简单,就是在调用flash视频播放器的时候,加上一个参数“o ...
- IPX/SPX
转自百度百科 方便阅读 IPX/SPX 目 录 1英文原义 2中文释义 3IPX协议 3.1 说明 3.2 应用 4SPX协议 4.1 说明 4.2 应用 1英文原义 IPX/SPX 2中 ...
- 自己写的SqlHelper
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- Synchronized vs SyncRoot
我们知道,在.net的一些集合类型中,譬如Hashtable和ArrayList,都有Synchronized静态方法和SyncRoot实例方法,他们之间有联系吗?我怎么才能用好他们呢?我们以Hash ...