IOS 自己定义UITableView
依据不同须要,须要使用tableview的结构,可是里面每个cell,又须要自己的样式。所以学习了一下如何把自定义的cell加到tableview里面
首先要自己创建一个类,继承UITableViewCell,然后新建一个空的xib文件,并在class属性设置为相应的类名
代码部分:
<pre name="code" class="objc">
#import "SettingViewController.h"
#import "SettingViewCell.h"
@interface SettingViewController ()
@end
@implementation SettingViewController
@synthesize listArray =_listArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSArray *array = [NSArray arrayWithObjects: @"房间设置",@"灯光设置",@"窗帘设置",@"场景设置",@"空调设置",@"安防设置",@"网络设置",nil];
_settingview.dataSource =self; //设置数据源方法
_settingview.delegate =self;//设置代理方法
self.listArray =array; //注意。因为内存管理问题。假设不正确self.listArray进行赋值,则_listArray会被清空。程序会崩溃
}
- (IBAction)backClicked:(id)sender {
[self.navigationController popToRootViewControllerAnimated:YES];
}
//数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_listArray count];
}
//托付方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch(indexPath.row)
{
case 0:
break;
default:
break;
}
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellIdentifier =@"mycell";
SettingViewCell *cell =(SettingViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
NSArray *array =[[NSBundle mainBundle] loadNibNamed:@"SettingViewCell" owner:self options:nil];
cell = [array objectAtIndex: 0];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
}
NSString *text = _listArray[indexPath.row];
[[cell settingName] setText:text];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_back release];
[_settingview release];
[super dealloc];
}
@end
IOS 自己定义UITableView的更多相关文章
- iOS开发系列--UITableView全面解析
--UIKit之UITableView 概述 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信.QQ.新浪微博等软件基本上随处都是U ...
- IOS开发中UITableView(表视图)的滚动优化及自定义Cell
IOS开发中UITableView(表视图)的滚动优化及自定义Cell IOS 开发中UITableView是非常常用的一个控件,我们平时在手机上看到的联系人列表,微信好友列表等都是通过UITable ...
- 【iOS系列】- UITableView的使用技巧
[iOS系列]- UITableView的使用 UITableView的常用属性 indexpath.row:行 indexpath.section:组 separatorColor:分割线的颜色 s ...
- ios宏定义字符串
ios宏定义字符串 #define objcString(str) @""#str"" 使用效果: objcString(字符串)
- iOS开发之UITableView的使用
这一篇记录的是iOS开发中UITableView的使用,iOS中的UITableView跟Android中的ListView特别相似,以下用一个Demo来说明: 1.Xcode中新建projectTe ...
- iOS Programming Editing UITableView
iOS Programming Editing UITableView 1.1 Editing mode UITableView has an editing property, and when ...
- Ios 该图显示其出现的相关问题定义UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
解决这个问题 在 加上个 标示符 Cell 自己定义 customCell .h 代码例如以下 ViewController.m 文件里 代码例如以下 执行结果 吕 图坚持直接在这里 不行
- iOS开发之UITableView使用总结
什么是UITableView 在众多移动应用中,能看到各式各样的表格数据 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView UITableView继承自UIScrollVie ...
- iOS 8自动调整UITableView和UICollectionView布局
本文转载自:http://tech.techweb.com.cn/thread-635784-1-1.html 本文讲述了UITableView.UICollectionView实现 self-siz ...
随机推荐
- JavaScript-事件冒泡简介及应用
一.什么是事件冒泡 在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事件返回true,那么这个事 ...
- 验证码显示不出来,在THINKPHP中的使用
未开启 php_gd2设置 php的配置文件php.ini,搜索extension=php_gd2.dll,去掉前面的分号即可: 1.在模块类中增加一个 verify 方法来用于显示验证码Public ...
- 【SJSB】 android-javascript开发框架
这是一个本人开发的android壳,作用就是为html5开发提供各种接口以调用native. 只是第一个版本,随笔以纪念.详细的说明和api都在 项目的readme中. 项目地址: https://g ...
- 【iOS与EV3混合机器人编程系列之三】编写EV3 Port Viewer 应用监測EV3port数据
在前两篇文章中,我们对iOS与EV3混合机器人编程做了一个主要的设想.而且介绍了要完毕项目所需的软硬件准备和知识准备. 那么在今天这一篇文章中,我们将直接真正開始项目实践. ==第一个项目: EV3 ...
- jquery书写左右两个多选下拉列表交换移除功能
使用jquery做一个多选列表左右互换的功能,代码如下 <!DOCTYPE HTML> <html lang="en-US"> <head> & ...
- Windows+IIS结合LVS+Keepalived是实现Linux负载均衡软件
在Discuz!NT的最新版本(企业版)中,支持目前主流LINUX平台上的负载均衡解决方案,比如NGINX,HAPROXY,LVS等.本文与其说是解决方案,倒不如说是介绍如何搭建Discuz!NT负载 ...
- Mybatis中insert
<insert id="insert" parameterType="Currency"> INSERT INTO YZ_SECURITIES_CU ...
- JavaScript 中的陷阱
JavaScript 通过函数管理作用域.在函数内部声明的变量只在这个函数内部,函数外面不可用.另一方面,全局变量就是在任何函数外面声明的或是未声明直接简单使用的. “未声明直接简单使用”,指的是不用 ...
- LeetCode - Employees Earning More Than Their Managers
Description: The Employee table holds all employees including their managers. Every employee has an ...
- IIS 无法访问.net的动态文件
编译器错误消息:CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319... 在“c:\windows\temp”这个文件夹添 ...