//
// 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. DEV GridControl导出到Excel或打印

    //方法1SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.Title = "导出Excel"; fileD ...

  2. 【JS】导出table到excel,同时兼容FF和IE

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. base库中的BarrierClosure

    说明说得很明白,就是等侍num_closures 为零的时候回调done_closure,代码也很简单,不加详述 #ifndef BASE_BARRIER_CLOSURE_H_ #define BAS ...

  4. MySQL取得当前时间的函数是什么 格式化日期的函数是什么

    取得当前时间用 now() 就行.在数据库中格式化时间 用DATE_FORMA T(date, format) .根据格式串format 格式化日期或日期和时间值date,返回结果串. 可用DATE_ ...

  5. Oracle EBS-SQL (BOM-9):检查系统BOM总数.sql

    SELECT      ITM.SEGMENT1                         物料编码     ,ITM.DESCRIPTION                     物料描述  ...

  6. ISO和UDF光盘格式、扩展ISO9660----Joliet和Romeo文件系统

    ISO和UDF光盘格式.扩展ISO9660----Joliet和Romeo文件系统 刻录DVD盘,当文件大于2G的时候,Nero会提示NERO选文件时提示无法刻录这么大的文件,请转换格式.这到底是怎么 ...

  7. H面试程序(29):求最大递增数

    要求:求最大递增数 如:1231123451 输出12345 #include<stdio.h> #include<assert.h> void find(char *s) { ...

  8. CentOS Linux 中文输入法安装及设置

    安装: 1.需要root权限,所以要用root登录 ,或su root 2.yum install "@Chinese Support" 3.exit 4.回到桌面,system- ...

  9. JavaScript代码编写尝试使用Vanilla JS 或者Jquery插件

    From Here: http://vanilla-js.com/ Vanilla JS is a fast, lightweight, cross-platform frameworkfor bui ...

  10. Linux网络设备驱动架構學習(三)

    Linux网络设备驱动架構學習(三) 接下來會從以下幾個方面介紹網絡設備驅動的編寫流程: 1.網絡設備的註冊與註銷 2.網絡設備的初始化 3.網絡設備的打開與釋放 4.網絡數據發送流程 5.網絡數據接 ...