TableView实现QQ好友列表效果

概述:本文是黑马程序员UI视频教程第九天,QQ好友列表案例的总结

该案例中主要涉及的知识点有:改变图片在UIButton中的平铺方式、UITableViewHeaderFooterView、设置按钮中图片和文本的内边距和对齐方式、tableView中按组进行重载、自定义delegate协议、layoutSubViews方法、巧妙传递用户的单击信息等内容

基本思路

  1. 使用UITableviewController,拷贝素材、创建界面、字典转模型,懒加载
  2. 实现tableView的数据源方法
  3. 设置headerView
  4. 实现点击headerView箭头旋转效果
  5. 实现点击headerView好友列表展开效果
  6. 实现VIP会员名称显示为红色

最终效果如下:

最终效果

1、拷贝素材、创建界面、字典转模型及懒加载

  • 该案例中仅包含一个tableView,因此使用一个tableViewController开始将更方便。删除原来的viewController,创建新的tableViewController,然后使其成为初始控制器initial View。创建基于UITableViewController的子类,并将其挂在创建的tableViewController下。
  • 注意该plist文件为字典嵌套字典的结构,因此字典转模型也需要分两层来写

2、实现TableView的数据源方法

  • 指定tableView的Section,- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

  • 指定tableView每个Section的行数,- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

  • 指定tableView每行所使用的Cell,-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

    从效果上看单元格的形式与subtitle形式的单元格基本一致,可以在代理方法内部使用标准subtitle形式的单元格并为内部控件赋值。但由于我们还要进行更多细节的调整,将单元格单独实现更有利于后续的改进,代码的可读性高。

    因为每个单元格的形式基本一致,可以考虑使用xib文件来创建单元格

    1. 创建xib单元格
    2. 创建基于UITableViewCell的子类,并与xib文件进行挂接。该子类中应包含LJFriend成员(或者将LJFriend对象作为参数传递给创建单元格的类方法)
    3. 实现创建单元格的类方法,重写LJFriend成员的set方法。在set方法中根据是否是vip设置昵称的字体颜色是否为红色
    #import <UIKit/UIKit.h>
    #import "LJFriend.h"
    
    @interface LJFriendCell : UITableViewCell
    @property(nonatomic , strong) LJFriend * friendCell_model;
    
    +(instancetype)friendCellWi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用QTableView实现翻页功能。下面是一个简单的示例代码: ```cpp #include <QApplication> #include <QTableView> #include <QStandardItemModel> #include <QPushButton> #include <QVBoxLayout> int main(int argc, char *argv[]) { QApplication app(argc, argv); // 创建数据模型 QStandardItemModel model; model.setColumnCount(1); model.setRowCount(100); // 假设有100条数据 // 创建表格视图 QTableView tableView; tableView.setModel(&model); // 设置每页显示的行数 int rowsPerPage = 10; // 创建翻页按钮 QPushButton previousButton("Previous"); QPushButton nextButton("Next"); // 创建布局管理器 QVBoxLayout layout; // 将表格视图和按钮添加到布局中 layout.addWidget(&tableView); layout.addWidget(&previousButton); layout.addWidget(&nextButton); // 设置布局管理器 QWidget window; window.setLayout(&layout); // 当前页数 int currentPage = 0; // 点击上一页按钮时的响应 QObject::connect(&previousButton, &QPushButton::clicked, [&]() { if (currentPage > 0) { currentPage--; tableView.scrollTo(model.index(currentPage * rowsPerPage, 0)); } }); // 点击下一页按钮时的响应 QObject::connect(&nextButton, &QPushButton::clicked, [&]() { if (currentPage < model.rowCount() / rowsPerPage) { currentPage++; tableView.scrollTo(model.index(currentPage * rowsPerPage, 0)); } }); window.show(); return app.exec(); } ``` 这个示例中,通过点击"Previous"和"Next"按钮可以切换表格视图中的页数。每页显示的行数可以通过`rowsPerPage`变量设置。你可以根据自己的需要修改代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值