//
// 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. asp.net 获取IP地理位置的几个主要接口

    腾讯的IP地址API接口地址:http://fw.qq.com/ipaddress 新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup ...

  2. 开启MSSQLServer跨服务器查询功能

    首先在MSSQL客户端中进行如下图文操作配置 其次使用脚本进行操作配置 ---开启SQLServer 跨服务器查询功能 exec sp_configure 'show advanced options ...

  3. php输出json中文显示编码-解决办法

    $str = "中华人民共和国";$ar = array( "a" => "a0", "b" => &quo ...

  4. EC读书笔记系列之19:条款49、50、51、52

    条款49 了解new-handler的行为 记住: ★set_new_handler允许客户指定一个函数,在内存分配无法获得满足时被调用 ★Nothrow new是一个颇为局限的工具,∵其只适用于内存 ...

  5. .Net之垃圾回收算法

    垃圾回收器检测托管堆中是否有应用程序不在使用的任何对象,如果一次垃圾回收之后,堆栈没有可用的内存,new操作符将会抛出OutOfMemoryException(内存溢出). 每一个应用程序都包含一组根 ...

  6. Spring随笔 - 事务隔离级别

    Spring提供5中事务隔离级别: ISOLATION_DEFAULT:使用数据库后端的默认隔离级别. ISOLATION_READ_UNCOMMITTED:允许读取尚未提交的数据变更.可能会导致脏读 ...

  7. Mvc Webapi+Fiddler调试 (WebAPI 一)

    Fiddler Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的“进出”Fiddler的数据(指cookie,html,js, ...

  8. 线程-run和start

    import java.lang.Thread; class Machine extends Thread{ public void run() { int a ; for( a = 0 ; a &l ...

  9. python学习day2(二)

    1.类与对象的关系 对于Python,一切事物都是对象,对象基于类创建 type是获取类的 dir是获取这个类里面的成员 2.int内部功能介绍 bit_length:返回表示当前数字占用的最少位数: ...

  10. Hibernate防止SQL注入

    如果在查询字段中输入单引号"'",则会报错,这是因为输入的单引号和其他的sql组合在一起编程了一个新的sql,实际上这就是SQL注入漏洞,后来我在前台和后台都对输入的字符进行了判断 ...