//
// 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. Windows计算器使用详解

    (1)Backspace:退格,删除当前输入数字中的最后一位 (2)CE:清除,清除显示的数字. (3)C:归零,清除当前的计算. (4)MC:清除存储器中的数值. (5)MR:将存于存储器中的数显示 ...

  2. 将项目上传到bitbucket仓库

    先将项目添加git仓库中(本地) 成功后上门会有上传和下载按钮 提交代码:

  3. C#l连接OPC进行数据交互

    步骤 :引用 OPCNETAPI.DLL&&OPCNETAPI.COM.DLL 1.查询服务器      2. 连接服务器  3. 读取数据     4.写入数据 1.查询服务器 :根 ...

  4. Powerdesigner逆向工程从sql server数据库生成pdm (完整版)

    第一步:打开"控制面板"中的"管理工具" 第二步:点击"管理工具"然后双击"数据源(odbc)" 第三步:打开之后,点击 ...

  5. [ZT]DAS\NAS\IP SAN\FC SAN之区别

    DAS:服务器直接后挂存储设备,最经济的一种结构. NAS:网络上直接挂接的存储设备,其实就是处于以太网上的一台利用NFS.CIFS等网络文件系统的文件共享服务器. SAN是网络上的磁盘,NAS是一个 ...

  6. 十个最值得阅读学习的C开源项目代码

    1. Webbench Webbench 是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以 模拟3万个并 ...

  7. 解析处理常用json数据总结

    工作中用ajax接收到接口返回的数据需要进行解析后操作,这里总结一下平时的方法,用的jquery,复制下来的页面把引入的路径改一下即可. <!DOCTYPE html> <html ...

  8. JavaScript判断IE各版本完美解决方案

    解决方案 IE知道自身毛病很多,于是提供的一套官方的HTML hack方式: <!--[if IE]> // 全部IE版本可见 <![endif]--> <!--[if ...

  9. HDU4738【杭州网赛、判桥】

    刚拿到这道题时挺有思路,无奈平日里只敲过找割顶的代码,判桥的代码当时自己也没仔细敲. 当时一把泪啊,忽然感觉自己的图论才只是刚搞了个起步啊.. 题目有神坑.    就是先判是否连通,不连通直接输出0; ...

  10. 微信公众帐号开发。大家是用框架还是自己写的流程。现在遇到若干问题。请教各路大仙 - V2EX

    微信公众帐号开发.大家是用框架还是自己写的流程.现在遇到若干问题.请教各路大仙 - V2EX 微信公众帐号开发.大家是用框架还是自己写的流程.现在遇到若干问题.请教各路大仙