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 ...
随机推荐
- angular ajax的使用及controller与service分层
一个简单的例子,控制层:.controller('publishController',['$scope','publishService', function($scope,publishServi ...
- 存储过程不返回记录集导致ADO程序出错
HRESULT _hr = get_adoEOF(&_result); IsEOF()函数如下:其中ADOCG::_RecordsetPtr m_pRecordset; BOOL IsEOF( ...
- require() 方法讲解
require.config({ paths:{ "jquery":"jquery.min", "underscore":"und ...
- Navicat for MySQL使用手记(上)--创建数据库和表
在管理MySQL数据库的图形化工具中,最为熟知的就是phpMyAdmin和Mysql-Front了,今天跟大家分享另外一个管理mysql数据库的另外一个利器---Navicat MySQL. Navi ...
- foreach使用
1. 读取记录while($row=mysql_fetch_array($result)){$record[]=array( 'title'=>$row['title'], 'body'= ...
- 改善C#程序的建议5:引用类型赋值为null与加速垃圾回收
http://www.cnblogs.com/luminji/archive/2011/04/07/2007205.html 在标准的Dispose模式中(见前一篇博客“C#中标准Dispose模式的 ...
- 超全面的JavaWeb笔记day22<文件上传>
文件上传概述 1 文件上传的作用 例如网络硬盘!就是用来上传下载文件的. 在智联招聘上填写一个完整的简历还需要上传照片呢. 2 文件上传对页面的要求 上传文件的要求比较多,需要记一下: 1. 必须使用 ...
- J2EE开发推荐工具
- 查看进程动态:top
top命令用于查看进程动态,即进程使用系统资源的情况,常见用法如下: [root@localhost ~]$ top # 动态查看进程使用资源的情况,每三秒刷新一次 [root@localhost ~ ...
- 改变PS1的颜色
我们能够通过配置PS1变量使提示符成为彩色.在PS1中配置字符序列颜色的格式为: \[\e[F;Bm\] 基本上是夹在 "\e["(转义开方括号)和 &qu ...