iOS UITableViewCell UITableVIewController 纯代码开发
iOS UITableViewCell UITableVIewController 纯代码开发 <原创> .纯代码 自定义UITableViewCell 直接上代码
//////
#import <UIKit/UIKit.h> @interface CodeTableViewCell : UITableViewCell
@property (nonatomic, weak) UIImageView *iconView;
@property (nonatomic, weak) UILabel *labName;
+ (instancetype)cellWithTableView:(UITableView *)tableView;
@end
///
#import "CodeTableViewCell.h"
#define NJNameFont [UIFont systemFontOfSize:15]
#define NJTextFont [UIFont systemFontOfSize:16]
@implementation CodeTableViewCell + (instancetype)cellWithTableView:(UITableView *)tableView {
// NSLog(@"cellForRowAtIndexPath");
static NSString *identifier = @"status";
// 1.缓存中取
CodeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
// 2.创建
if (cell == nil) {
cell = [[CodeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell;
}
/**
* 构造方法(在初始化对象的时候会调用)
* 一般在这个方法中添加需要显示的子控件
*/
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// 让自定义Cell和系统的cell一样, 一创建出来就拥有一些子控件提供给我们使用
// 1.创建头像
UIImageView *iconView = [[UIImageView alloc] init];
[self.contentView addSubview:iconView];
self.iconView = iconView; // 2.创建昵称
UILabel *nameLabel = [[UILabel alloc] init];
nameLabel.font = NJNameFont;
nameLabel.textColor=[UIColor redColor];
[self.contentView addSubview:nameLabel];
self.labName = nameLabel;
[self.contentView setBackgroundColor:[UIColor clearColor]];
[self settingFrame];
}
return self;
}
//设置相对位置
- (void)settingFrame
{
self.frame = CGRectMake(, , , );
self.labName.frame=CGRectMake(, /-, , );
self.iconView.frame=CGRectMake(, (-)/, , );
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; // Configure the view for the selected state
}
@end
//////
. 通常写UITableView 都是 在UIViewController里面定义一个UITableView,现在直接让当前控制器继承于UITableViewController,避免写繁文缛节的死代码,更方便.但是table view controller 只限于管理一个全屏展示的 table view。
最后,你需要把迁移后丢失的 table view controller 的特性给补回来。大多数都是 viewWillAppear: 或 viewDidAppear: 中简单的一条语句。
直接上代码:
#import <UIKit/UIKit.h> @interface RootViewController : UITableViewController @end
/////
#import "RootViewController.h"
#import "CodeTableViewCell.h"
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UITableView *tableViewMine;
}
@end @implementation RootViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor yellowColor];
// tableViewMine=[[UITableView alloc]initWithFrame:self.view.frame];
// [self.view addSubview:tableViewMine];
// tableViewMine.delegate=self;
// tableViewMine.dataSource=self;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat
{//调用 自定义的tableViewCell
CodeTableViewCell *cell=[CodeTableViewCell cellWithTableView:tableView];
cell.labName.text=@"sssssssssss";
cell.iconView.image=[UIImage imageNamed:@"iconhead.jpg"];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld",indexPath.row);
}
/*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
///////////
上效果图:
iOS UITableViewCell UITableVIewController 纯代码开发的更多相关文章
- springboot整合elasticJob实战(纯代码开发三种任务类型用法)以及分片系统,事件追踪详解
一 springboot整合 介绍就不多说了,只有这个框架是当当网开源的,支持分布式调度,分布式系统中非常合适(两个服务同时跑不会重复,并且可灵活配置分开分批处理数据,贼方便)! 这里主要还是用到zo ...
- Masonry -- 使用纯代码进行iOS应用的autolayout自适应布局
简介 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstraints. 项目主页: Masonry 最新示例: 点击下载 项目简议: 如果再看到关于纯代 ...
- Masonry — 使用纯代码进行iOS应用的autolayout自适应布局
本文转载至 http://www.ios122.com/2015/09/masonry/ 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstrain ...
- 从表单驱动到模型驱动,解读低代码开发平台的发展趋势 ZT
原文地址:https://www.grapecity.com.cn/blogs/read-the-trends-of-low-code-development-platforms 随着社会数字化进程的 ...
- ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局
本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...
- 李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView
李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView (VTmagic是一个实现左右滚动的控制器的框架,也可以实现此功能) 实现的效果: 01 - 创建四个控制器 02 - 定义需要 ...
- iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController)
iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController) 这里我们就直接上实例: 一:新建一个项目singleV ...
- iOS开发——OC篇&纯代码退出键盘
关于iOS开发中键盘的退出,其实方法有很多中,而且笔者也也学会了不少,包括各种非纯代码界面的退出. 但是最近开始着手项目的时候却闷了,因为太多了,笔者确实知道有很多中方法能实现,而且令我影响最深的就是 ...
- 【好程序员笔记分享】——iOS开发之纯代码键盘退出
-iOS培训,iOS学习-------型技术博客.期待与您交流!------------ iOS开发之纯代码键盘退出(非常简单) iOS开发之纯代码键盘退出 前面说到了好几次关于键盘退出的,但 ...
随机推荐
- Oracle 查询用户表信息,导入导出处理表空间不一致
select table_name,tablespace_name from user_tables t; //查询用户默认表空间信息 SELECT t.* FROM USER_USERS t; 导入 ...
- HTML to PDF pechkin
1. Goto Nuget 下载 Pechkin 控件 2. 创建需要打印的的PDF controller 和 Action, 这里会调用其他页面的内容进行打印. public ActionResul ...
- Catch That Cow(广度优先搜索_bfs)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 48036 Accepted: 150 ...
- group by having和connect by
--使用group by 子句对数据进行分组:对group by 子句形成的组运行聚集函数计算每一组的值:最后用having 子句去掉不符合条件的组.--having 子句中的每一个元素也必须出现在s ...
- full join 时通过辅助列序号列消除笛卡尔积重复列
如果没有序号列,那么如果领灯表里有3条数据,还灯表里面有2条数据,full join后就是3*2=6条数据 --1.领灯表,每天每班每人允许重复数据 select ID ,ROW_NUMBER() o ...
- asp.net core mvc视频A:笔记2-3.高级数据绑定
默认的绑定顺序,如果需要取指定数据源里的数据,需要通过属性控制,比如[FromQuery] 前端 控制器方法 前端 此时并不能得到head中的数据 改造控制器方法,添加[FromHeader]属性 再 ...
- 教你用squid做CDN把公司做到上市
我们都知道CDN(内容分发网络)是用来给网站加速用的,通过在现有的Internet中增加一层新的网络架构,将网站的内容发布到最接近用户的网络的“边缘”,使用户可以就近取得所需的内容,以提高用户访问网站 ...
- Unmapped Spring configuration files found.
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架后,IDEA弹出如下提示: 2.解决方案: File --> Project Structure --> M ...
- linux命令的别名alias,unalias
1. 别名 linux别名alias的作用: 1. 简化特别长得命令和參数 2. 对一些命令添加默认选项.提高安全性. 2. alias使用 [www@work sh]$ alias lm='ls - ...
- Sphinx初探之安装
在Centos or redhat 安装Sphinx .首先安装依赖包 $ yum install postgresql-libs unixODBC .安装软件 $ rpm -Uhv sphinx-- ...