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 ...
随机推荐
- 如何POST一个JSON格式的数据给Restful服务
在Android/java平台上实现POST一个json数据: JSONObject jsonObj = new JSONObject(); jsonObj.put("username&qu ...
- oracle数据备份
from:http://www.docin.com/p-728428621.html
- VS------修改项目命名空间
1.以文本形式打开此文件 2.修改一下部分 3.vs会自动提示,选择“放弃”即可
- svn 操作字母的提示
今天使用SVN提交代码,发现提交后的代码找不到之前的版本. 操作的字母缩写为R.一般我们常见的操作为 A D M R A:add,新增 C:conflict,冲突 D:delete,删除 M:mo ...
- js实现卡号每四位空格分隔
window.onload =function() { document.getElementById("input_num").oninput =function() { })( ...
- Android移动网络如何抓取数据包
1)下载tcpdump工具 tcpdump(dump the traffic on a network)是Linux中强大的网络数据采集分析工具之一,可以将网络中传送的数据包头完全截获下来提供分析.它 ...
- shell基础篇(九)函数
函数可以让我们将一个复杂功能划分成若干模块,让程序结构更加清晰,代码重复利用率更高.像其他编程语言一样,Shell 也支持函数.Shell 函数必须先定义后使用1. Shell 函数的定义格式如下: ...
- CentOS6.5安装图形界面(Gnome)
因为是以最小化安装的Linux,无法使用图形界面,从网上看到资料,我使用yum安装果然很简单 ----------------------------------------------------- ...
- cocos2d-x游戏引擎核心之二——内存管理
(一) cocos2d-x 内存管理 cocos2d里面管理内存采用了引用计数的方式,具体来说就是CCObject里面有个成员变量m_uReference(计数); 1, m_uReference的变 ...
- spring AOP底层原理实现——jdk动态代理
spring AOP底层原理实现——jdk动态代理