参考 “https://www.cnblogs.com/ai-developers/p/4557487.html”

UITableViewCell 有一个代码重用 减少资源的浪费

参考  https://www.cnblogs.com/ai-developers/p/4562311.html

这里没有写

#import "ViewController.h"

@interface ViewController ()

//引用UITableView

@property (nonatomic,strong)UITableView * tableView;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self MyTableView];

}

//代码简洁化

-(void) MyTableView

{

//创建一个不分组的TableView  分组的下一节

self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

//TableView 的背景颜色

self.view.backgroundColor = [UIColor whiteColor];

//绑定数据源 需要实现两个方法 也可以设置section的数量

//-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

//  -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

//-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath

self.tableView.dataSource = self;

//添加到TableView的主屏幕

[self.view addSubview:self.tableView];

}

//实现rows

-(NSInteger)tableView :(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return 4;

}

//实现section

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 4;

}

//实现数据的绑定

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath

{

//实例化一个默认样式的cell  可更改

UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

//设置cell 的文本  类似于lable

cell.textLabel.text = [NSString stringWithFormat:@"section is %lu,Row is %lu",(long)indexPath.section,(long)indexPath.row];

return cell;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

实现的结果:

ios学习笔记 UITableView(纯代码) (一)的更多相关文章

  1. ios学习笔记 UITableView(纯代码) (二)

    头文件 --------------------------------------------- #import <UIKit/UIKit.h> /** UITableViewDataS ...

  2. iOS: 学习笔记实例, 用代码控制视图创建与切换

    1. 创建iOS, Single View Application.2. 修改YYViewController.m // // YYViewController.m // DynamicViewDem ...

  3. iOS学习笔记(4) — UITableView的 重用机制

    iOS学习笔记(4) — UITableView的 重用机制 UITableView中的cell是动态的,在使用过程中,系统会根据屏幕的高度(480)和每个cell的高度计算屏幕中需要显示的cell的 ...

  4. iOS学习笔记之UITableViewController&UITableView

    iOS学习笔记之UITableViewController&UITableView 写在前面 上个月末到现在一直都在忙实验室的事情,与导师讨论之后,发现目前在实验室完成的工作还不足以写成毕业论 ...

  5. [置顶] iOS学习笔记47——图片异步加载之EGOImageLoading

    上次在<iOS学习笔记46——图片异步加载之SDWebImage>中介绍过一个开源的图片异步加载库,今天来介绍另外一个功能类似的EGOImageLoading,看名字知道,之前的一篇学习笔 ...

  6. IOS学习笔记48--一些常见的IOS知识点+面试题

      IOS学习笔记48--一些常见的IOS知识点+面试题   1.堆和栈什么区别? 答:管理方式:对于栈来讲,是由编译器自动管理,无需我们手工控制:对于堆来说,释放工作由程序员控制,容易产生memor ...

  7. iOS学习笔记-自己动手写RESideMenu

    代码地址如下:http://www.demodashi.com/demo/11683.html 很多app都实现了类似RESideMenu的效果,RESideMenu是Github上面一个stars数 ...

  8. iOS学习笔记20-地图(二)MapKit框架

    一.地图开发介绍 从iOS6.0开始地图数据不再由谷歌驱动,而是改用自家地图,当然在国内它的数据是由高德地图提供的. 在iOS中进行地图开发主要有三种方式: 利用MapKit框架进行地图开发,利用这种 ...

  9. iOS学习笔记——AutoLayout的约束

    iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...

随机推荐

  1. MTK平台下Battery驱动分析

    主要涉及代码: Kernel: kernel-3.10\drivers\power\mediatek\ kernel-3.10\drivers\misc\mediatek\mach\mt6580\&l ...

  2. Mac开发必备工具(三)—— Fish shell

    Fish shell 简介 fish 可以根据输入自动匹配历史命令.它的一大特点是开箱即用,没有zsh那些繁琐的配置.官网:http://www.fishshell.com/. 安装与配置 在终端里使 ...

  3. eclipse4.3 解决没有check out as maven project

    最近想工作之余写点测试demo,习惯了公司的开发环境,便决定自己搭建开发环境,首先是找到好用的eclipse,就是能够使用eclipse创建maven project工程,该工程能够被eclipse的 ...

  4. android广播接收器

    Android程序创建广播接收器继承BroadcastReceiver Android广播接收器需要在AndroidManifest.xml文件中声明: <recevie android:nam ...

  5. Erlang-VM节点启动名冲突问题

    今天在启动聊天的ErlangVM后,在日志中发现错误信息: Protocol 'inet_tcp': the name chatserver@127.0.0.1 seems to be in use ...

  6. [Selenium] common functions comparison

    1.Wait for element  in default time or self defined time When the element need some time to be prese ...

  7. ES6之拷贝对象

    function copyObject(orig) { var copy = Object.create(Object.getPrototypeOf(orig)); //创建一个新的原型对象 copy ...

  8. 替换一个文件中的内容BAT

    @echo off setlocal enabledelayedexpansion set file=%1set "file=%file:"=%" for %%i in ...

  9. appium九宫格解锁错误提示:The coordinates provided to an interactions operation are invalid解决办法

    原文地址:http://blog.csdn.net/qqtMJK/article/details/77838814 今天做自动化解锁9宫格,发现swipe不能满足需求,于是用TouchAction去实 ...

  10. perceptron and ANN

    %% Perceptron Regression close all clear %%load data x = load('ex4x.dat'); y = load('ex4y.dat'); x=o ...