关于继承UITableViewController若干问题
//
// MSHomeCommentTableViewController.m
// xiaoqu-ios
//
// Created by Charlie on 15/7/1.
// Copyright (c) 2015年 meimeidou. All rights reserved.
// #import "MSHomeCommentTableViewController.h" @interface MSHomeCommentTableViewController ()<UITabBarControllerDelegate,UITableViewDataSource,UITableViewDelegate>
{
BOOL _isMoreDataIng; } @end @implementation MSHomeCommentTableViewController
-(NSMutableArray *)dataArr
{
if (!_dataArr)
{
_dataArr =[NSMutableArray array];
}
return _dataArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
_isMoreDataIng = NO ;
[self getDataFromServer];
[self.refreshControl addTarget:self action:@selector(getDataFromServer) forControlEvents:UIControlEventValueChanged];//自带的刷新控件
[self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; //观察者 观察上拉加载更多数据
}
#pragma mark 从服务器获取数据
- (void)getDataFromServer
{ }
- (void)getMoreDataFromServer
{ }
#pragma mark -上拉加载更多函数
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([object isKindOfClass:[self.tableView class]]) {
CGFloat offset=[[change objectForKey:@"new"] CGPointValue].y ; if (offset > self.tableView.contentSize.height-self.tableView.frame.size.height)
{
NSLog(@"%.0f",offset);
if (!_isMoreDataIng)
{
_isMoreDataIng = YES ; //记录刷新状态
[self getMoreDataFromServer];// 记载更多数据
} } }
}
/*
#pragma mark - doneRefresh
- (void)doneRefresh
{
double delayInSeconds = 0.3;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[_refreshControl endRefreshing];
_isLoadMoreProcessing = NO;
});
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return self.dataArr.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.clickRowBlock) {
self.clickRowBlock ((int)indexPath.row); //传递观察者
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * cellID = @"ThemeCellId";
MSThemeTableViewCell * cell ;
cell =[tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell =[[MSThemeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
cell.selectionStyle = UITableViewCellSelectionStyleNone ;
}
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[cell configDataWithModel:self.dataArr[indexPath.row]];
return cell;
} -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{ }
- (void)dealloc
{
[self.tableView removeObserver:self forKeyPath:@"contentOffset"]; //删除 观察者
}
@end
可能有些同学也是这样子写的,没问题,但是 就是tableview上的view 粘贴到其他view上好像没有反应,
_tableView=[[MSHomeCommentTableViewController alloc]init];
_tableView.tableView.frame = CGRectMake(, , kScreenWidth, kScreenHeight);
[self.view addSubview:_tableView.tableView];
好像没问题,但是还是每出来。
最后想半天,原来是数据源没有。
再加上这数据源就OK了
- (void)configData
{
_tableView.dataArr =[_dataArray mutableCopy];
}
加上这个函数就OK 了。
关于继承UITableViewController若干问题的更多相关文章
- ios 继承UITableViewController,更改tableview样式
// 继承UITableViewController,更改tableview样式 - (instancetype)initWithStyle:(UITableViewStyle)style { ret ...
- iOS基础 - UITableViewController
1. 继承UITableViewController默认会设置数据源和代理,并且会自动遵守数据源和代理协议,并且self.tableView 相当于 self.view 2.更换控制器时,注意把sto ...
- [iOS UI进阶 - 2.2] 彩票Demo v1.2 UICollectionView基本
A.需要掌握的 设计.实现设置界面 cell的封装 UICollectionView的使用 自定义UICollectionView 抽取控制器父类 "帮助"功能 code sour ...
- iOS总结_UI层自我复习总结
UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...
- FMDB简单封装和使用
工具:火狐浏览器+SQLite Manager插件 ; Xcode; FMDB库; 效果: 项目地址: https://github.com/sven713/PackFMDB 主要参考这两篇博客: 1 ...
- OS开发UI篇—使用UItableview完成一个简单的QQ好友列表
本文转自:http://www.cnblogs.com/wendingding/p/3763330.html 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableVi ...
- iOS开发——UI进阶篇(三)自定义不等高cell,如何拿到cell的行高,自动计算cell高度,(有配图,无配图)微博案例
一.纯代码自定义不等高cell 废话不多说,直接来看下面这个例子先来看下微博的最终效果 首先创建一个继承UITableViewController的控制器@interface ViewControll ...
- iOS学习24之UIControl及其子类
1. UIControl初识 1> 概述 UIControl是有控制功能的视图( 如UIButton.UISlider.UISegmentedControl等)的父类 只要跟控制有关的控件都是继 ...
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...
随机推荐
- Spring-----1、Spring简介和Spring3.0的变化
转载自:http://blog.csdn.net/hekewangzi/article/details/41324441
- js查找元素
1.className <!DOCTYPE html> <html> <head lang="en"> <meta charset=&qu ...
- jcSQL词法分析器对字符串token的解析
上星期写完词法分析器的时候,曾遇上一个无关紧要却X疼的问题.毕竟是第一次完整地写整个语言的编译器(暂且这么叫着吧,解释器更靠谱),由于经验不足,在字符串解析这一块驻足了两天才解决掉,这里记录下来供以后 ...
- FLASH MAGIC LPC ISP下载方式说明
硬件:EASYARM2131 开发板软件:FLASH MAGIC 下载地址:http://www.flashmagictool.com/程序:Demo2131.hex LPC的ISP下载方式, ...
- delphi 文件搜索,遍历所有子目录
function ListFiles(path: string): TStringList; var SearchRec: TSearchRec; found: integer; begin resu ...
- de4dot命令 v2.0.3.3405
de4dot v2.0.3.3405 Copyright (C) 2011-2013 [email]de4dot@gmail.com[/email] Latest version and source ...
- CC++初学者编程教程(7) 搭建Windows EclipseCCPP软件开发环境
1根据电脑是32位还是64位来选择工具 2 查看电脑是64位 3 管理员身份运行这个文件 4 安装JDK64位 5. 下一步 6 开始安装 7 安装JAVA 8 安装进行时 9 安装成功 10解压缩 ...
- UITabBarController 笔记(一)AppDelegate中加UITabBarController 为 rootViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- Java 可中断线程
PART.1 无法中断的线程 一个无法中断的线程的例子. public class UninterruptableThread { @SuppressWarnings("deprecatio ...
- 自定义Toast样式-两行文本居中显示
toast可以设置自定义的view和显示位置.下面是一个简单的例子,复杂些的就是改变其布局文件就可以了. /** * @author BMR * @ClassName: ToastWithTwoTex ...