//
// 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若干问题的更多相关文章

  1. ios 继承UITableViewController,更改tableview样式

    // 继承UITableViewController,更改tableview样式 - (instancetype)initWithStyle:(UITableViewStyle)style { ret ...

  2. iOS基础 - UITableViewController

    1. 继承UITableViewController默认会设置数据源和代理,并且会自动遵守数据源和代理协议,并且self.tableView 相当于 self.view 2.更换控制器时,注意把sto ...

  3. [iOS UI进阶 - 2.2] 彩票Demo v1.2 UICollectionView基本

    A.需要掌握的 设计.实现设置界面 cell的封装 UICollectionView的使用 自定义UICollectionView 抽取控制器父类 "帮助"功能 code sour ...

  4. iOS总结_UI层自我复习总结

    UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...

  5. FMDB简单封装和使用

    工具:火狐浏览器+SQLite Manager插件 ; Xcode; FMDB库; 效果: 项目地址: https://github.com/sven713/PackFMDB 主要参考这两篇博客: 1 ...

  6. OS开发UI篇—使用UItableview完成一个简单的QQ好友列表

    本文转自:http://www.cnblogs.com/wendingding/p/3763330.html 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableVi ...

  7. iOS开发——UI进阶篇(三)自定义不等高cell,如何拿到cell的行高,自动计算cell高度,(有配图,无配图)微博案例

    一.纯代码自定义不等高cell 废话不多说,直接来看下面这个例子先来看下微博的最终效果 首先创建一个继承UITableViewController的控制器@interface ViewControll ...

  8. iOS学习24之UIControl及其子类

    1. UIControl初识 1> 概述 UIControl是有控制功能的视图( 如UIButton.UISlider.UISegmentedControl等)的父类 只要跟控制有关的控件都是继 ...

  9. iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)

    iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...

随机推荐

  1. C# 数组的应用

    //数组的应用: //(一).冒泡排序. //1.冒泡排序是用双层循环解决.外层循环的是趟数,里层循环的是次数. //2.趟数=n-1:次数=n-趟数. //3.里层循环使用if比较相临的两个数的大小 ...

  2. Hql参数占位符使用(转+整理)

    在Hibernate 4版本中,对于Hql有一点点改变,如果你还是按照以前的方式去编写HQL Query query = sessionFactory.openSession().createQuer ...

  3. JUnit报空指针错误,控制台不报任何错误

    解决方法:1. 在测试类的beforeClass方法上加try-catch块 2. 添加main方法,里面添加beforeClass();

  4. 【原】YUI3:js加载过程及时序问题

    时序问题在javascript中比较常见,尤其是在网络环境不稳定时以及某些浏览器本来版本中比较多,遇到此类问题,往往会使开发者非常头痛,问题的重现需要特定的环境,是偶发的,不容易重现.对于有经验的开发 ...

  5. weiphp 微信公众号用程序来设置指定内容消息回复业务逻辑操作

    微信公众号机器人回复设置 在公众号插件里面的Robot- Model- weixinAddonModel.php里面的 reply设置 reply($dataArr,$keywordArr) 解析方法 ...

  6. CSS自学笔记(16):CSS3 用户界面

    CSS3中,也新增了一些关于用户界面的属性,这些属性可以重设元素或者盒子的尺寸.轮廓等等. 新增的部分属性的浏览器支持情况 属性 浏览器支持 resize IE Firefox Chrome Safa ...

  7. linux----LAMP之编译安装apache

    第一步:解决依赖.安装apr.apr-util. apr-1.5.4.tar.gz下载地址:http://yunpan.cn/cFBzgsC3rDcyR  访问密码 4c82 apr-util-1.5 ...

  8. linux 如何禁用账号和解除禁用账号

    把账号禁用可以有几个方法:1. # usermod -L <username> # usermod -U <username> // 解除禁用2. 修改/etc/passwd文 ...

  9. linux GUI程序开发

    1,C++ OOP中 class与C 面向过程开发中struct非常相似

  10. Hibernate 、多表关联映射 - 一对一关系映射(one- to-one)

    hibernate.cfg.xml: <hibernate-configuration> <session-factory name="sessionFactory&quo ...