`
修博龙泉
  • 浏览: 317042 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

fenye

 
阅读更多

#import "WTAlbumImVC.h"
#import "WTPullRefreshView.h"
#import "WTAlbumPicListCell.h"
#import "WTPictureDetailVC.h"

@interface WTAlbumImVC () <WTPullRefreshViewDelegate, WTPictureDetailVCDelegate>
// picture list view
@property (retain, nonatomic) IBOutlet UIView *picListView;
@property (retain, nonatomic) IBOutlet UITableView *picTableView;
@property (retain, nonatomic) WTPullRefreshView *picPullRefreshView;

// im view
@property (retain, nonatomic) IBOutlet UIView *imView;


// picture list view data source
@property (retain, nonatomic) NSMutableArray *picArray;
@property (assign, nonatomic) BOOL picHasMore;
@property (retain, nonatomic) NSString *picCursor;
// im view data source

@end

@implementation WTAlbumImVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (UIBarButtonItem*)createBackBarButton
{
    //定制自己的风格的  UIBarButtonItem
    UIImage* image= [UIImage imageNamed:@"back.png"];
    UIImage* imagef = [UIImage imageNamed:@"back_focus.png"];
   
    CGRect backframe= CGRectMake(0, 0, image.size.width, image.size.height);
   
    UIButton* backButton= [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = backframe;
    [backButton setBackgroundImage:image forState:UIControlStateNormal];
    [backButton setBackgroundImage:imagef forState:UIControlStateHighlighted];
    [backButton addTarget:self action:@selector(onBackButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
   
    UIBarButtonItem* someBarButtonItem= [[[UIBarButtonItem alloc] initWithCustomView:backButton] autorelease];
    return someBarButtonItem;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = _album.albumName;
    UIViewController *rootVC = [self.navigationController.viewControllers objectAtIndex:0];
    if (rootVC == self || _dismissWhenExit) {
        self.navigationItem.leftBarButtonItem = [self createBackBarButton];
    }
   
    self.picPullRefreshView = [[[WTPullRefreshView alloc] initWithTableView:_picTableView refreshOn:YES loadMoreOn:NO] autorelease];
    _picPullRefreshView.delegate = self;
   
    if (!self.picArray) {
        // first time load
        self.picArray = [NSMutableArray arrayWithCapacity:100];
        [_picPullRefreshView triggerPullRefresh];
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [TMRequest cancelRequestsWithDelegate:self];
    self.picListView = nil;
    self.picTableView = nil;
    self.picPullRefreshView = nil;
    self.imView = nil;
   
    self.picArray = nil;
    self.picCursor = nil;

    [super dealloc];
}



- (void)viewDidUnload {
    self.picListView = nil;
    self.picTableView = nil;
    self.picPullRefreshView = nil;
    self.imView = nil;

    [super viewDidUnload];
}


#pragma mark - User Click Methods
- (void)onBackButtonClicked:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

- (void)onPictureClicked:(WTPicture *)aPicture {
    WTPictureDetailVC *detailVC = [[[WTPictureDetailVC alloc] init] autorelease];
    NSUInteger index = [_picArray indexOfObject:aPicture];
    detailVC.hidesBottomBarWhenPushed = YES;
    [detailVC setDisplayIndex:index inPictureArray:_picArray hasMore:_picHasMore cursor:_picCursor delegate:self];
    [self.navigationController pushViewController:detailVC animated:YES];
}

#pragma mark - Network Methods
- (void)getPictureListSuccess:(TMRequest *)aRequest{
    BOOL refresh = (aRequest.tag==1);
    if (refresh) {
        [_picArray removeAllObjects];
    }
    TMCursorArray *cursorArray = aRequest.result;
    if (cursorArray.array) {
        [_picArray addObjectsFromArray:cursorArray.array];
    }
    self.picHasMore = cursorArray.hasMore;   
    self.picCursor = cursorArray.cursor;

    _picPullRefreshView.needLoadMoreData = cursorArray.hasMore;
   
    [_picTableView reloadData];
    [_picPullRefreshView didFinishLoadingSuccess:YES];
}

- (void)getPictureListFail:(TMRequest *)aRequest{
    [_picPullRefreshView didFinishLoadingSuccess:NO];
}


- (void)getPictureListFromServerByRefresh:(BOOL)aRefresh {
    TMRequest *request = [[WTAlbumService sharedInstance] getPictureListByAlbumId:_album.albumId cursor:aRefresh?nil:_picCursor];
    [request setDelegate:self successSel:@selector(getPictureListSuccess:) failSel:@selector(getPictureListFail:)];
    if (aRefresh) {
        request.tag = 1;
    }
    [request runAsync];
}

#pragma mark - WTPictureDetailVC Delegate Methods

- (void)pictureDetailVC:(WTPictureDetailVC *)aVC
          exitAtPicture:(WTPicture *)aPicture
         inPictureArray:(NSArray *)anArray
                hasMore:(BOOL)aHasMore
                 cursor:(NSString *)aCursor
{
    if ([_picPullRefreshView isLoading]) {
        // 正在加载或者刷新的话,取消请求,避免数据异常
        [TMRequest cancelRequestsWithDelegate:self];
        [_picPullRefreshView didFinishLoadingSuccess:NO];
    }
   
    if ([_picArray count] < [anArray count]) {
        // more data loaded
        [_picArray removeAllObjects];
        [_picArray addObjectsFromArray:anArray];
        self.picHasMore = aHasMore;
        self.picCursor = aCursor;
        _picPullRefreshView.needLoadMoreData = self.picHasMore;
        [_picTableView reloadData];       
    }
   
    int position = NSNotFound;
    for (int i=0; i<[_picArray count]; i++) {
        WTPicture *temp = [_picArray objectAtIndex:i];
        if ([temp.picId isEqualToString:aPicture.picId]) {
            position = i;
            break;
        }
    }
   
    if (position != NSNotFound) {
        int picCount = position + 1;
        int rowCount = picCount / 3;
        int mod = picCount % 3;
        if (mod > 0) {
            rowCount++;
        }
        int rowIndex = rowCount-1;
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0];
        [_picTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];       
    }
}

- (TMRequest *)pictureDetailVC:(WTPictureDetailVC *)aVC requestForLoadMoreWithCursor:(NSString *)aCursor {
    return [[WTAlbumService sharedInstance] getPictureListByAlbumId:_album.albumId cursor:aCursor];
}

- (void)pictureDetailVC:(WTPictureDetailVC *)aVC didPictureDisplayed:(WTPicture *)aPicture {
   
    NSUInteger count = [self.picArray indexOfObject:aPicture]+1; // 加1是因为计算在第几行的时候,是按照个数来算的
    int rowCount = count / 3;
    int mod = count % 3;
    if (mod > 0) {
        rowCount++;
    }
    int rowIndex = rowCount-1;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0];
    [_picTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
}




#pragma mark - UITableView Delegate Methods

//指定每个分区中有多少行,默认为1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    int row = [_picArray count] / 3;
    int mod = [_picArray count] % 3;
    if (mod > 0) {
        row ++;
    }
    return row;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 105;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"WTAlbumPicListCell";
   
    WTAlbumPicListCell *cell = (WTAlbumPicListCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell == nil){
        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"WTAlbumPicListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    int index1 = indexPath.row * 3;
    int index2 = indexPath.row * 3 + 1;
    int index3 = indexPath.row * 3 + 2;
    WTPicture *pic1 = [_picArray objectAtIndex:index1];
    WTPicture *pic2 = nil;
    if (index2 < [_picArray count]) {
        pic2 = [_picArray objectAtIndex:index2];
    }
    WTPicture *pic3 = nil;
    if (index3 < [_picArray count]) {
        pic3 = [_picArray objectAtIndex:index3];
    }
   
    [cell setPic1:pic1 pic2:pic2 pic3:pic3];
    cell.delegate = self;
   
    return cell;
}




#pragma mark -
#pragma mark WTPullRefreshViewDelegate UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView == _picTableView) {
        [_picPullRefreshView scrollViewDidScroll:scrollView];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView == _picTableView) {
        [_picPullRefreshView scrollViewDidEndDragging:scrollView];
    }
}


#pragma mark WTPullRefreshViewDelegate Methods

- (void)pullRefreshViewDidTriggerRefresh:(WTPullRefreshView *)aPullFreshView {
    if (aPullFreshView == _picPullRefreshView) {
        [self getPictureListFromServerByRefresh:YES];
    }
}

- (void)pullRefreshViewDidTriggerLoadMore:(WTPullRefreshView *)aPullFreshView {
    if (aPullFreshView == _picPullRefreshView) {
        [self getPictureListFromServerByRefresh:NO];
    }
}


@end
分享到:
评论

相关推荐

    s2_h_fenye

    "s2_h_fenye"这个压缩包可能包含了一个用于数据库分页的模板代码,适用于学习和实际项目中。 数据库分页通常涉及以下几个关键知识点: 1. **SQL查询**:分页查询通常通过SQL语句实现,利用`LIMIT`(MySQL)或`...

    fenye.jsp数据库的分页功能

    fenye.jsp代码,是为了实现分页功能,就是实现数据库信息与jsp相连接的数据的分页查看功能

    oracle_fenye.zip

    使用struts2和hibernate实现oracle分页源文件,提供完整可以运行的源代码,运行环境myeclipse8.5、myeclipse2016,struts2 版本,hibernate3以上版本

    sql-2008-fenye.zip_doc

    本资料"sql-2008-fenye.zip_doc"包含了关于如何在SQL Server 2008中实现分页存储过程的详细信息,并且提供了一个转换为.doc格式的文档。 分页查询的基本概念是限制从数据库检索的数据量,通常用于Web应用中的表格或...

    jquery-fenye.zip_java分页_jquery

    本项目“jquery-fenye.zip”是关于Java后端与jQuery前端结合实现的一个小型分页功能的示例。下面将详细阐述相关知识点。 首先,我们来看Java分页。在Java Web应用中,分页通常在服务端进行,因为这有助于减少前端的...

    FenYe.jar 封装了hibernate分页

    这个jar包太好了 真是神通啊,它封装了hibernate分页 请大家在项目中 用一下 挺好用的 我自己创建的名称:FenYe.jar 欢迎大家下载!!!!

    fenye.css

    fenye.css

    jsp_fenye.rar_jsp分页

    jsp分页演示,带文档分析,sqlserver2005

    java--fenye-.rar_java_java分页_工具 java

    在Java编程领域,分页是数据管理中一个非常重要的概念,特别是在处理大量数据时,为了提高用户体验和系统性能。分页允许用户逐步加载和查看数据,而不是一次性加载所有记录,这样可以减少内存消耗并加快页面加载速度...

    fenye:这是一个有关分页的项目,里面会有相关的模版工具类,以便以后用的时候可以直接拿来用

    标题中的"fenye"是一个关于分页的项目,它包含了一些模板工具类,方便开发者在后续的项目中直接复用。 该项目的核心是实现一个纯手工的分页工具类,这意味着没有依赖任何特定的库或框架,这在某些场景下特别有用,...

    ejb分页技术解决读取数据库占用内存问题

    1. 首先,创建一个JavaBean类,例如`FenYe`,用于处理分页逻辑: ```java public class FenYe { private ResultSet CountTopicrs; private ResultSet Pagirs; private int intCountTopic; private int int...

    比较简便的分页包,该分页只限用于web工程

    //------------3${fenye.view}[按钮样式] ${fenye.viewb}[链接样式] &lt;/td&gt;&lt;/tr&gt; ${fenye.view} 此时重载有几个方法: 控制器类: A. MyPager.getPager(List list,HttpServletRequest request); B.MyPager....

    详细jsp分页程序/有注释说明

    &lt;form method="POST" action="fenye1.jsp"&gt; 第页 共页 (intPage){%&gt; href="fenye1.jsp?page=&lt;%=intPage+1%&gt;"&gt;下一页 &lt;/a&gt;&lt;%}%&gt; (intPage&gt;1){%&gt;&lt;a href="fenye1.jsp?page=&lt;%=intPage-1%&gt;"&gt;

    碳强度相关数据(学习使用)zip

    1. HK_pilu_fenye.csv:可能代表香港的电力消耗或碳排放的分区数据,"fenye"可能表示分年度或分季度的数据。 2. HK_fenye.csv:可能包含香港的整体碳排放数据,同样可能是按时间序列划分的。 3. HK_strength_fenye....

    A股、港股上市公司碳排放、碳强度和碳披露数据(2018-2021年).zip

    数据集中的"HK_strength_fenye.csv"和"A_strength_fenye.csv"文件分别提供了港股和A股上市公司在不同年度的碳强度数据,便于比较不同公司的环境绩效。 再者,“碳披露”是指企业主动公开其温室气体排放信息的行为,...

    分页javabean

    1. **分页参数**:在`FenYe.java`中,可能会定义一些属性来存储分页所需的参数,如当前页码(currentPage)、每页记录数(pageSize)、总记录数(totalRecords)以及总页数(totalPages)。 2. **构造方法**:为了...

    js实现table分页可以动态生成table

    接下来,`fenye.js`和`gettab.js`是JavaScript文件,它们负责处理表格数据的加载、分页逻辑和用户交互。在`fenye.js`中,我们可以定义分页函数,例如: ```javascript function pagination(data, pageSize) { let ...

    目前用到的两个分页存储过程代码

    首先,我们来看第一个存储过程`[sq8reyoung].[fenye_num]`,它的主要目的是计算满足特定条件的数据总行数。这个存储过程接受两个参数:`@TableNames`(要查询的表名)和`@Filter`(查询条件)。如果`@Filter`为空,...

    java自定义标签分页

    在本案例中,"page.tld"文件就是TLD文件,它定义了自定义标签"fenye"的相关信息,包括标签名、属性等。"fenye.jar"是包含了自定义标签处理类和相关资源的库文件,这个库需要被添加到项目的类路径中以便使用。 分页...

    超简单的分面自定义标签(含源码)

    具体使用时,开发者需要在JSP页面中引入"TLD"文件,然后在适当位置插入自定义标签,例如`&lt;fenye:pagination/&gt;`,并设置必要的属性如当前页数、每页条目数等。自定义标签内部会根据这些属性进行计算,并生成相应的...

Global site tag (gtag.js) - Google Analytics