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 纯代码开发的更多相关文章

  1. springboot整合elasticJob实战(纯代码开发三种任务类型用法)以及分片系统,事件追踪详解

    一 springboot整合 介绍就不多说了,只有这个框架是当当网开源的,支持分布式调度,分布式系统中非常合适(两个服务同时跑不会重复,并且可灵活配置分开分批处理数据,贼方便)! 这里主要还是用到zo ...

  2. Masonry -- 使用纯代码进行iOS应用的autolayout自适应布局

    简介 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstraints. 项目主页: Masonry 最新示例: 点击下载 项目简议: 如果再看到关于纯代 ...

  3. Masonry — 使用纯代码进行iOS应用的autolayout自适应布局

    本文转载至   http://www.ios122.com/2015/09/masonry/ 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstrain ...

  4. 从表单驱动到模型驱动,解读低代码开发平台的发展趋势 ZT

    原文地址:https://www.grapecity.com.cn/blogs/read-the-trends-of-low-code-development-platforms 随着社会数字化进程的 ...

  5. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  6. 李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView

    李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView (VTmagic是一个实现左右滚动的控制器的框架,也可以实现此功能) 实现的效果:  01 - 创建四个控制器 02 - 定义需要 ...

  7. iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController)

    iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController)   这里我们就直接上实例: 一:新建一个项目singleV ...

  8. iOS开发——OC篇&纯代码退出键盘

    关于iOS开发中键盘的退出,其实方法有很多中,而且笔者也也学会了不少,包括各种非纯代码界面的退出. 但是最近开始着手项目的时候却闷了,因为太多了,笔者确实知道有很多中方法能实现,而且令我影响最深的就是 ...

  9. 【好程序员笔记分享】——iOS开发之纯代码键盘退出

    -iOS培训,iOS学习-------型技术博客.期待与您交流!------------ iOS开发之纯代码键盘退出(非常简单)     iOS开发之纯代码键盘退出 前面说到了好几次关于键盘退出的,但 ...

随机推荐

  1. 控制器View是怎样创建的?

    对于非常多程序猿来说控制器和View的关系肯定有点模糊,对于View的创建肯定有一种说不清道不明的感觉.view仅仅是控制器的一个属性.控制器中有很多对view处理的方法.也就是说得控制器管理view ...

  2. windows 网站迁移到linux

    从windows迁移网站到linux 发现乱码 出现这种情况的原因为两种操作系统的中文压缩方式不同,在windows环境中中文一般为gbk,而在linux环境中为utf8,这就导致了在windows下 ...

  3. Machine Learning——Unsupervised Learning(机器学习之非监督学习)

    前面,我们提到了监督学习,在机器学习中,与之对应的是非监督学习.无监督学习的问题是,在未加标签的数据中,试图找到隐藏的结构.因为提供给学习者的实例是未标记的,因此没有错误或报酬信号来评估潜在的解决方案 ...

  4. 【Hadoop基础教程】1、Hadoop之服务器基础环境搭建(转)

    本blog以K-Master服务器基础环境配置为例分别演示用户配置.sudo权限配置.网路配置.关闭防火墙.安装JDK工具等.用户需参照以下步骤完成KVMSlave1~KVMSlave3服务器的基础环 ...

  5. Http调试工具-Fiddler使用指引

    转自:http://my.oschina.net/u/1388024/blog/186886#OSC_h1_9 目录[-] Fiddler是什么? Fiddler能做什么? 从哪里下载? 安装: 初次 ...

  6. 篇三、开发前知识补充:Android的长度单位和屏幕分辨率,这个也是转载~~

    这篇文章有点早,不过很实用.单位的实用看最后的红色标注的部分. 屏幕分辨率基础 1.术语和概念 术语 说明 备注 Screen size(屏幕尺寸) 指的是手机实际的物理尺寸,比如常用的2.8英寸,3 ...

  7. ELK之jason配置nginx文件等多个配置文件

    [root@web02 ~]# cat /etc/logstash/conf.d/nginx.conf input { file { path => "/var/log/nginx/a ...

  8. 【Python+selenium Wendriver API】之下拉框定位

    上代码: # coding:utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains impo ...

  9. Java NIO —— Buffer(缓冲区)

    Buffer是一个抽象类,位于java.nio包中,主要用作缓冲区.注意:Buffer是非线程安全类. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO Buffer ...

  10. php 在linux 用file_exists() 函数判断 另外一台服务器映射过来的文件是否存在 总是返回false

    php 在linux 用file_exists() 函数判断 另外一台服务器映射过来的文件是否存在 总是返回false .如下案例 $type="android"; $url=&q ...