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. ibatis 读写clob数据

      ibatis 读写clob数据 CreationTime--2018年7月1日09点57分 Author:Marydon 1.从数据库读取数据 <!-- 根据主键查询患者信息.申请单.报告单 ...

  2. Dungeon Master ZOJ 1940【优先队列+广搜】

    Problem Description You are trapped in a 3D dungeon and need to find the quickest way out! The dunge ...

  3. 我攻克了oom

    BitmapFactory.Options options=new BitmapFactory.Options();     options.inJustDecodeBounds = false;   ...

  4. 如何快速复制BAT级的DevOps工具链

    1.流水线改变世界 1910年,福特汽车在引入流水线生产之后,Model-T 的组装时间缩短了8倍,从12.5小时降到了1.5小时,这就是流水线改变世界的神话,造就了汽车上的国家! 那流水线怎么改变软 ...

  5. .Net 异步调用

    .NET异步编程之新利器——Task与Await.Async   一.  FrameWork 4.0之前的线程世界    在.NET FrameWork 4.0之前,如果我们使用线程.一般有以下几种方 ...

  6. .NET CORE 2.0小白笔记(三):数字化平台之微信平台策略

    当下,互联网技术正在深刻地重构我们的社会,各大企事业单位——大到万人集团公司,小到图文复印店——都在争先恐后地从所谓的“传统行业”中脱胎换骨一番以完成数字化转型. 在这个过程中,“企业即IT”.“科技 ...

  7. .NET CORE 2.0小白笔记(二):VS插件 ReSharper Ultimate 2017 安装破解

    采用Use License Server方式激活,如果有多台要激活的可以用一个当服务器 下载网盘:链接: https://pan.baidu.com/s/1nvacvKP 密码: ipxc 版本:Je ...

  8. Windows 清除系统垃圾文件

    @echo off echo 正在清除系统垃圾文件,请稍等...... del /f /s /q %systemdrive%\*.tmp del /f /s /q %systemdrive%\*._m ...

  9. SpringBoot使用MyBatis报错:Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)

    © 版权声明:本文为博主原创文章,转载请注明出处  1. 错误描述 使用SpringBoot集成MyBatis框架,并且使用 mapper-spring-boot-starter 自动生成MyBati ...

  10. 数据库操作事物的四大特性以及MySQL数据库的四种隔离级别

    1 .事物操作数据库的四大特性(ACID) 1.原子性 (Atomicity) 原子性:就是事物的所包含的所有操作,要么全部成功,要么全部失败回滚. 2.一致性 (Consistency) 一致性:简 ...