IOS 之 UITableView

iOS UITableView(一)布局介绍 简介 UITableView是iOS开发中使用较为频繁的视图。在很多地方都用到了它来展示数据,比如微信通讯录和新闻列表等。 在UITableView中,分节、分组和索引等功能让我们展示的数据更加规整,更有条理。 1.概述 本节将主要介绍UITableView中的概念、相关类、表视图分类、单元格组成和样式,以及表视图的两个协议——UITableViewDelegate委托和UITable... 阅读详情

需要实现的协议:

UITableViewDelegate

UITableViewDataSource

 

数据源:

//
//  DataSet.m
//  TableViewDemo
//
//  Created by zhangqiang on 14-5-17.
//  Copyright (c) 2014年 zhangqiang. All rights reserved.
//

#import "DataSet.h"

@implementation DataSet


- (id) initWithDataSet
{
    array=[NSArray arrayWithObjects:[[MeEntry alloc] initWithMeEntry:@"title1" subtitle:@"subtitle1" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/0" ofType:@"png"]] contents:@"contents1"],
           [[MeEntry alloc] initWithMeEntry:@"title2" subtitle:@"subtitle1" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/0" ofType:@"png"]] contents:@"contents2"]
           ,[[MeEntry alloc] initWithMeEntry:@"title3" subtitle:@"subtitle2" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/1" ofType:@"png"]] contents:@"contents3"]
           ,[[MeEntry alloc] initWithMeEntry:@"title4" subtitle:@"subtitle3" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/2" ofType:@"png"]] contents:@"contents4"]
           ,[[MeEntry alloc] initWithMeEntry:@"title5" subtitle:@"subtitle4" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/3" ofType:@"png"]] contents:@"contents5"]
           ,[[MeEntry alloc] initWithMeEntry:@"title6" subtitle:@"subtitle5" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/4" ofType:@"png"]] contents:@"contents6"]
           ,[[MeEntry alloc] initWithMeEntry:@"title7" subtitle:@"subtitle6" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/5" ofType:@"png"]] contents:@"contents7"]
           ,[[MeEntry alloc] initWithMeEntry:@"title8" subtitle:@"subtitle7" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/6" ofType:@"png"]] contents:@"contents8"]
           ,[[MeEntry alloc] initWithMeEntry:@"title9" subtitle:@"subtitle8" headimage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resource/7" ofType:@"png"]] contents:@"contents9"], nil];
    return self;
}

- (NSArray*) GetData
{
    return array;
}

@end


实体类:

//
//  MeEntry.m
//  TableViewDemo
//
//  Created by zhangqiang on 14-5-17.
//  Copyright (c) 2014年 zhangqiang. All rights reserved.
//

#import "MeEntry.h"

@implementation MeEntry
@synthesize title,subtitle,headImage,contents;
- (id) initWithMeEntry:(NSString *)title subtitle:(NSString *)subtitle headimage:(UIImage *)headImage contents:(NSString *)contents
{
    self.title=[NSString stringWithString:title];
    self.subtitle=[NSString stringWithString:subtitle];
    self.headImage=headImage;
    self.contents=[NSString stringWithString:contents];
    return self;
}
@end

 

UITableViewDelegate 协议实现:

//
//  ViewController.m
//  TableViewDemo
//
//  Created by zhangqiang on 14-5-17.
//  Copyright (c) 2014年 zhangqiang. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    ds=[[DataSet alloc] initWithDataSet];
    index=0;
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[ds GetData] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *data=[ds GetData];
    UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
    if(cell==nil)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
    }
    MeEntry * me=(MeEntry*)data[index];
    cell.imageView.image=me.headImage;
    cell.textLabel.text=me.title;
    cell.detailTextLabel.text=me.contents;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    index++;
    if([data count]-index==1)
    {
        index=0;
    }
    return cell;
}

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *data=[ds GetData];
    MeEntry * me=(MeEntry*)data[indexPath.row];
    cell.textLabel.text= me.title;
    NSLog(@"willDisplayCell: %@",cell.textLabel.text);
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *data=[ds GetData];
    MeEntry * me=(MeEntry*)data[indexPath.row];
    NSString *msg=[NSString stringWithFormat:@"当前选择标题:%@",me.title];
    
    UIAlertView *alertview=[[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alertview show];
    NSLog(@"didSelectRowAtIndexPath");
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
}

- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"didDeselectRowAtIndexPath");
}


@end



 

iOS中使用UITableView加载数据项 ios中用UITableView加载数据 实现步骤 1:添加数据源和数据代理模式 2:设置数据源和代理 3:实现 具体步骤如下: 1:添加数据源和数据代理模式 在oc中添加的方法如下图1位置标注 在@interface viewcontrol()后面用“ 第二步: 在程序加载时设置table的数据源和数据代理模式代码如下:... 阅读详情

相关推荐

iOS小技能:1. 什么是UITableView? 2. UITableView如何展示数据

文章目录引言I UITableView的简介1.1 什么是UITableView?1.2 UITableView如何展示数据(代理模式)II 字典转模型举例2.1 嵌套字典数组的模型转化2.2. KVC 之数组取值III MVC(model、view、controller)3.1 MVC的特性3.2 MVC特性的应用 引言 iOS开发中,要实现表格数据展示,做常用的做法就是使用UITableView。 I UITableView的简介 1.1 什么是UITableView? UITableView继承自U

专注于计算机研发知识和资讯分享 1511

从 iOS 向 ASP.NET WebServices 发送数据

我第一个 iOS 上的项目需求:利用 iOS 拍照功能在工作现场拍照;并对照片进行文字描述;最后将照片和文字描述上传到服务器。 需求分为两个功能点: 1. 调用 iOS 的拍照功能 2. 调用 iOS 的无线功能上传数据 第一点好办,iOS 为简单的拍照功能提供了一个控件 UIImagePickerControler,而且还有官方的例程 PhotoPicker 供参考。

摘花换酒的专栏 2093

从零到一:手把手教你构建自定义ReaxFF力场参数

本文手把手教你从零构建自定义ReaxFF力场参数,详解反应力场的动态键序机制与参数化逻辑。通过LAMMPS实战演示,涵盖训练数据准备、参数优化算法选择及性能优化技巧,助力研究人员精准模拟化学反应过程。适用于材料科学、催化研究等领域,特别适合已掌握分子动力学基础的进阶用户提升力场开发能力。

weixin_28365523的博客 1057

IOS 上传图片到ASP.NET

ASP.NET服务端的代码: 1. protected void Page_Load(object sender, EventArgs e) 2. { 3. if (Request.Files.Count == 0) 4. { 5. Response.Write("none file"); 6. } 7. els...

iteye_8029的博客 147

测试 Wi-Fi、蓝牙性能

前几天去原厂测试了 Wi-Fi 和蓝牙的性能,现在把了解到的知识总结一下 RF通路新理解 RF通路一般分为两部分:芯片端、天线端 芯片端 芯片端包括芯片+芯片出来的RF匹配电路,是来调芯片的阻抗匹配的。 天线端 天线前一般也会有一段天线匹配电路,是留给天线调天线的阻抗匹配的。 调试的时候是两部分分开调试的,下面调试的就是芯片端。 测试“阻抗匹配”用网络分析仪看史密斯圆图 测试...

撒哈拉的初学者的博客 1万+

灵魂三问:因果推断

什么是因果推断?为什么研究因果推断?怎么进行因果推断研究?

ML OR 智能决策的博客 2902

ios UITableview使用

/* * 视图加载完毕 初始化 */ -(void)myViewDidLoadInit { self.TV_MyCustomer.delegate = self; self.TV_MyCustomer.dataSource = self; //去除边框 self.TV_MyCustomer.separatorStyle = NO; //绑定cell

u011740841的专栏 442

周志华《机器学习》课程系列笔记——目录导航页

最近自学机器学习课程,注意到了南京大学周志华老师的课程。我是在学堂在线平台观看的,注意到b站上也有相应视频,但b站上并未获得授权,随时有消失的可能。周志华老师的网络教学视频中,与其西瓜书相比确实少了一些内容。但幸运的是,缺失的内容实际上对于初学者来说并不会产生太大影响。目前这一笔记也遵循视频内容,相比西瓜书中也会有一些缺失,敬请谅解。可能以后如果有机会和时间,我会再阅读周志华老师的书籍将缺失内容补全。一切内容敬请关注我的个人Page页面。

Sinocifengs的博客 1686

iOS-UITableView常见用法

iOS-UITableView常见用法 UITableView是iOS中最常用的控件之一。使用UITableView可以展示列表,也可以展示复杂的滑动页面。代码如下: 1.创建UITableView。 /// 使用懒加载创建UITableView lazy var mainTableView: UITableView = { let tableView = UITableVie...

a479323208的博客 282

STC8G1K08A 实战应用:从配置到功能实现

本文详细介绍了STC8G1K08A单片机的实战应用,从开发环境搭建、GPIO配置、ADC模块使用到定时器中断处理和PWM输出等核心功能。重点讲解了外设模块的协同工作配置技巧,并分享了实际项目开发中的经验教训,帮助开发者快速掌握STC8G1K08A的高效应用。

n4o5p6q7r的博客 391

一站式讲解Wireshark网络抓包分析的若干场景、过滤条件及分析方法

本文详细讲解常用的抓包工具、抓包分析的网络场景、分析抓包时的多种过滤条件以及如何结合常用的协议去分析排查问题,给大家提供一个借鉴或参考。

dvlinker的技术专栏 5万+

IOS UITableView Group&Section

UItableView 根据数据结构不同 会有不同样式 关键在两个代理 tableviewdelegate&tabledatasourse 下面代码是我实施的Group 在模拟器中 ios6.1和ios7 并且滚动后相应的section会“置顶”,效果不错哦! 核心代码: #import <UIKit/UIKit.h> @interface Announcem...

weixin_34356555的博客 533

【AUTOSAR-CanNM】-3.1-如何让ECU发出的首帧是NM帧(Tx Nm报文先于Tx App应用报文发出)

如何让ECU发出的首帧是NM帧(Tx Nm报文先于Tx App应用报文发出)

「汽车电子助手」的博客 4724

iOS7 UITableView视图结构解析

UITableViewCell *cell=(UITableViewCell *)[[[textView superview] superview] superview];     UITableView *myTableView=(UITableView *)[[(UITableViewCell *)[[[textView superview] superview] supervi

Technolegy make dreams come true 2747

等保测评-瀚高数据库

一般适用于等保测评

m0_54146694的博客 1634

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

ios uitableview滚动到底部

代码示例相关视频讲解:数组-Go代码演示如何实现iOS UITableView滚动到底部 1. 整体流程 为了帮助你更好地理解如何实现iOS UITableView滚动到底部,我将整个过程分解为以下几个步骤,并给出每一步的具体操作和代码示例。 erDiagram PARTICIPANT[A 经验丰富的开发者] ...

weixin_40978856的博客 550

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

IOS UITableView删除功能

UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,比如购物车等。删除功能可以直接使用系统自带的删除功能,当横向轻扫cell时,右侧出现红色的删除按钮,点击删除当前cell。     使用系统自带删除功能的步骤: 1、让tableView进入编辑状态,也就是设置它的editing为YES 2、返回编辑模式,也就是实现UITableViewDelegate中的

无名 863

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

IOS学习 UITableView 委托方法

#import #define VIEW_WIDTH self.view.bounds.size.width #define VIEW_HEIGHT self.view.bounds.size.height #import "DetaiViewController.h" @interface HomeViewController : UIViewContro

ridxmc的博客 517

iOS中UITableView的编辑模式

iOS中UITableView的编辑模式 (1)编辑每一行 修改某行的accessoryType属性,这个属性可以设为四个常量: UITableViewCellAccessoryCheckmark UITableViewCellAccessoryDetailDisclosureButton UITableViewCellAccessoryDisclosureIndicator UITable

xujingjing 学习iOS开发历程 1833

iOS开发之UITableView的使用

这一篇记录的是iOS开发中UITableView的使用,iOS中的UITableView跟Android中的ListView特别相似,下面用一个Demo来说明: 1、Xcode中新建工程TestSimpleTableView工程 2、在Main.storyboard中拖入一个UITableView控件 3、在ViewController.h文件中,实现UITableViewDelegate和

记录技术,记录生活 4989

UITableView上的iOS UIRefreshControl

In this tutorial, we’ll be implementing UIRefreshControl on the UITableView in our iOS Application. You must have seen very often a spinning wheel when you pull the top of your screen in your iOS Appl...

从零开始的教程世界 441

IOS控件之UITableView详解

摘要 UITableView视图是IOS开发中常用而好用的一个控件。 IOS UITableView 表示图 目录[-] IOS中UITableView使用总结 一、初始化方法 二、常用属性 三、常用方法详解 四、tableView操作刷新块的应用 五、tableView的编辑操作 六、选中cell的相关操作 七、tableView附件的相关方法

qq_28884869的博客 493

IOS使用UItableView实现下拉菜单组件(UITableView的使用方法)

一. 基础版本 在登陆界面有时需要保存已经登陆的账号信息,可以点开一个下拉菜单选择保存的账号,这里是用UIKit的表格组件编写一个下拉菜单组件demo,实现思路如下: 1.首先在一个UIViewController里放一个按钮或者标签框,用来显示当前选中的账号,右边放一个打开下拉菜单的小按钮,点击按钮时打开菜单,菜单是一个UITableView,设置好显示框后,

西毒 3522
上一篇: C++ 字符编码转换工具类
下一篇: Java 加载Jar包
IT回忆录
博客等级 码龄16年 42粉丝 100原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值