Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何添加在UItableview中加载的footerview?_Iphone_Ios_Ipad - Fatal编程技术网

Iphone 如何添加在UItableview中加载的footerview?

Iphone 如何添加在UItableview中加载的footerview?,iphone,ios,ipad,Iphone,Ios,Ipad,我制作了一个UITableView,并从一个web服务从JSON获取数据 Firat,我想先得到前5个对象,然后将它们加载到我的tableView中。这是正确的 然后,我希望无论何时用户滚动到页脚..都应该获取接下来的5个对象,并在tableView中显示 我被困在这里了,有人能告诉我下一步怎么走吗 My tableview具有从不同类型的自定义类加载的所有自定义单元格 - (UIView *)tableView:(UITableView *)tableView viewForFooterInS

我制作了一个UITableView,并从一个web服务从JSON获取数据

Firat,我想先得到前5个对象,然后将它们加载到我的tableView中。这是正确的

然后,我希望无论何时用户滚动到页脚..都应该获取接下来的5个对象,并在tableView中显示

我被困在这里了,有人能告诉我下一步怎么走吗

My tableview具有从不同类型的自定义类加载的所有自定义单元格

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if(section==[array count]-1)
    {
        UITableViewCell *cell = [self tableView:mtableview1 cellForRowAtIndexPath:myIP];
        frame =  cell.contentView.frame;
        footerView  = [[UIView alloc] init];
        footerView.backgroundColor=[UIColor clearColor];
        self.activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
        self.activityIndicator.hidesWhenStopped=YES;

        self.activityIndicator.center = CGPointMake(65,50);
        [self.activityIndicator startAnimating];

        UILabel* loadingLabel = [[UILabel alloc]init];
        loadingLabel.font=[UIFont boldSystemFontOfSize:12.0f];
        loadingLabel.textAlignment = UITextAlignmentLeft;
        loadingLabel.textColor = [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0];
        loadingLabel.numberOfLines = 0;
        loadingLabel.text=@"Loading.......";
        loadingLabel.frame=CGRectMake(95,35, 302,25);

        loadingLabel.backgroundColor =[UIColor clearColor];
        loadingLabel.adjustsFontSizeToFitWidth = NO;
        [footerView addSubview:self.activityIndicator];
        [footerView addSubview:loadingLabel];
        [self performSelector:@selector(loadending) withObject:nil afterDelay:1.0];
        [loadingLabel release];

        NSLog(@"%f",mtableview1.contentOffset.y);
        mtableview1.tableFooterView=footerView;

        return footerView;
    }
    return nil; 
}

我一直这样做,但它的位置并不总是正确的。这是我的大问题。

您可以使用以下概念。概念是当用户拉动表视图,然后重新加载其他数据,如拉动刷新

Code Sample :
//MARK: -UIScrollViewDelegate
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView.contentOffset.y <= - 65.0f) {
        // fetch extra data & reload table view
    }
} 
代码示例:
//MARK:-UIScrollViewDelegate
-(void)ScrollViewDiEndDraging:(UIScrollView*)scrollView将减速:(BOOL)减速{

如果(scrollView.contentOffset.y使用UIScrollViewDelegate方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    }
在scrollViewDidScroll方法中,您可以检查调用加载方法的行索引

NSIndexPath *indexPath = [[self.myTable indexPathsForVisibleRows]objectAtIndex:1]; //in middle visible of row
int visibleRowIndex = indexPath.row;

当到达最后一行时,可以在表视图中增加行数,检查是否有更多内容要显示。如果有更多内容要显示,则增加行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

增加行数后,您可以滚动到想要显示的行…

我已经实现了这一点,请看这是我的代码

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{

    if(footerView == nil)
    {
        footerView  = [[UIView alloc] init];
        CGRect screenBounds = [[UIScreen mainScreen] bounds];

        if (ObjApp.checkDevice == 1)
        {
            UIImage *image = [[UIImage imageNamed:@"LoadMoreBtn.png"]
                              stretchableImageWithLeftCapWidth:8 topCapHeight:8];

            btnLoadMore = [UIButton buttonWithType:UIButtonTypeCustom];
            [btnLoadMore setBackgroundImage:image forState:UIControlStateNormal];
            if(screenBounds.size.height == 568)
            {
                //    iPhone 5
                [btnLoadMore setFrame:CGRectMake(74, 13, 148, 34)];
            }
            else
            {
                //    iPohne 4 and Older iPhones
               [btnLoadMore setFrame:CGRectMake(74, 13, 148, 34)];
            }
        }
        else if (ObjApp.checkDevice == 2)
        {
            UIImage *image = [[UIImage imageNamed:@"LoadMoreBtn_iPad.png"]
                              stretchableImageWithLeftCapWidth:8 topCapHeight:8];

            btnLoadMore = [UIButton buttonWithType:UIButtonTypeCustom];
            [btnLoadMore setBackgroundImage:image forState:UIControlStateNormal];
            [btnLoadMore setFrame:CGRectMake(220, 26, 296, 67)];
        }
        [btnLoadMore.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [btnLoadMore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btnLoadMore addTarget:self action:@selector(btnLoadmore_clicked:)
         forControlEvents:UIControlEventTouchUpInside];
        [footerView addSubview:btnLoadMore];
    }
    return footerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (ObjApp.checkDevice == 1)
    {
        return 47;
    }
    else
    {
        return 100;
    }
    return 0;
}

#pragma mark - Button Click Methods
-(void)btnLoadmore_clicked:(id)sender
{
    if(page > 0)
    {
        sendpage++;
        if(sendpage<= page)
        {
        [self loading];
        NSString *urlString = [NSString stringWithFormat:@"data={\"name\":\"%@\",\"lat\":\"%f\",\"page\":\"%d\",\"long\":\"%f\"}",txtSearchFld.text,ObjApp.current_Latitude,sendpage,ObjApp.current_Longitude];
        [WebAPIRequest WS_Search:self :urlString];

        CGFloat height = tblSearchResult.contentSize.height - tblSearchResult.bounds.size.height;
        [tblSearchResult setContentOffset:CGPointMake(0, height) animated:YES];
        }
    }
}
-(UIView*)表视图:(UITableView*)表视图页脚配置:(NSInteger)部分
{
如果(页脚视图==nil)
{
footerView=[[UIView alloc]init];
CGRect屏幕边界=[[UIScreen mainScreen]边界];
if(ObjApp.checkDevice==1)
{
UIImage*image=[[UIImage ImageName:@“LoadMoreBtn.png”]
可拉伸图像,左帽宽:8顶帽高:8];
btnLoadMore=[UIButton buttonWithType:UIButtonTypeCustom];
[btnLoadMore setBackgroundImage:状态的图像:UIControlStateNormal];
if(screenBounds.size.height==568)
{
//iPhone5
[btnLoadMore setFrame:CGRectMake(74,13,148,34)];
}
其他的
{
//iPohne 4和更老的iPhone
[btnLoadMore setFrame:CGRectMake(74,13,148,34)];
}
}
else if(ObjApp.checkDevice==2)
{
UIImage*image=[[UIImage ImageName:@“LoadMoreBtn_iPad.png”]
可拉伸图像,左帽宽:8顶帽高:8];
btnLoadMore=[UIButton buttonWithType:UIButtonTypeCustom];
[btnLoadMore setBackgroundImage:状态的图像:UIControlStateNormal];
[btnLoadMore setFrame:CGRectMake(220,26,296,67)];
}
[btnLoadMore.titleLabel setFont:[UIFont boldSystemFontOfSize:20];
[btnLoadMore setTitleColor:[UIColor whiteColor]用于状态:UIControlStateNormal];
[btnLoadMore添加目标:自我操作:@selector(btnLoadMore\u单击:)
forControlEvents:UIControlEventTouchUpInside];
[footerView添加子视图:btnLoadMore];
}
返回页脚视图;
}
-(CGFloat)表视图:(UITableView*)表视图页脚高度:(NSInteger)部分
{
if(ObjApp.checkDevice==1)
{
返回47;
}
其他的
{
返回100;
}
返回0;
}
#pragma标记-按钮单击方法
-(无效)已单击的btnLoadmore:(id)发件人
{
如果(页面>0)
{
sendpage++;

if(sendpage:您需要在底部加载更多内容?+1以提供问题解决方案的正确实现方式:)