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上让我来 ...
随机推荐
- How to delete a large number of data in SharePoint for List when refreshing data?
Preface Recently thequestion was asked in the newsgroups about deleting a large number of itemsfrom ...
- PAT---1001. A+B Format (20)
#include<stdio.h> int main(){ //定义要读入的两个整数 int a,b; //定义好放拆项用的数组 ]; //读入两个整数 scanf("%d%d& ...
- python学习笔记--Django入门一 网页显示时间
我的笔记是学习http://djangobook.py3k.cn/ 课程时做的,这个上边的文章讲的确实是非常的详细,非常感谢你们提供的知识. 上一篇随笔中已经配置好了Django环境,现在继续跟随ht ...
- spring jar包、文档官网下载
一.spring的官方网址:http://spring.io/ 二.看到这个简洁清新的界面,导航很明确,进入projects whatever the infrastructure needs of ...
- Base64算法
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/4288372.html ...
- div随另一个div自动增高
<script type="text/javascript"> document.getElementById("div1").style.heig ...
- HDFS的Java客户端操作代码(HDFS删除文件或目录)
1.HDFS删除文件或目录 package Hdfs; import java.io.IOException; import java.net.URI; import org.apache.hadoo ...
- 【转】关于C#接口和抽象类的一些说明
接口和抽象类 1.概念 什么是接口? 接口是包含一组虚方法的抽象类型,其中每一种方法都有其名称.参数和返回值. 接口方法不能包含任何实现,CLR允许接口可以包含事件.属性.索引器. 一个类可以实现多个 ...
- 学习java随笔第三篇:java的基本数据类型
数据类型 一:整型 1.十进制 2.八进制 八进制数是满8进1,包含0~7的8个数字,在整数前面添加一个"0",表示是八进制数. 3.十六进制 十六进制数是满16进1,包含0~9, ...
- Activity以singleTask模式启动,intent传值的解决办法
转载请注明出处,谢谢http://blog.csdn.net/harryweasley/article/details/46557827 因为项目中,有一个消息推送的功能,每次推送一个消息,就会开启F ...