单击按钮ios时,UItableview scrollsToTop不起作用

时间:2017-01-11 06:25:10

标签: ios uitableview scroll uicollectionview uicollectionviewcell

我正在水平方向滚动uicollection,在集合视图单元格内部我有两个表视图 - 一个_tablewView - 另一个_tblnoti,我已经添加了一个用于折叠订单卡的按钮,点击我要将_tableView滚动到顶部,但它无法正常工作

点击下拉按钮,重新加载 中的表格视图

 - (IBAction)btnDropdownclick:(UIButton*)sender
{

NSIndexPath *indesss = [NSIndexPath indexPathForItem:sender.tag-300 inSection:0];
 CollectionViewCell  *cell =  (CollectionViewCell*) [_InnercollectionView cellForItemAtIndexPath:indesss];
 _flag =indesss.item;

shouldCellBeExpanded = !shouldCellBeExpanded;

if(shouldCellBeExpanded)
{

    [sender setImage:[UIImage imageNamed:@"uparrow.png"] forState:UIControlStateNormal];


}
else
{
    [sender setImage:[UIImage imageNamed:@"downarrow.png"] forState:UIControlStateNormal];


}


cell.shouldCellBeExpanded = !cell.shouldCellBeExpanded ;


[_InnercollectionView performBatchUpdates:^{
    [cell.tabelView reloadData];





} completion:^(BOOL finished) {


}];

}

下面是单元格类中的代码

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath

 {


 if(_shouldCellBeExpanded){
        _heightcheckview.constant = _tabelView.contentSize.height+120;
        _tblheight.constant = _tabelView.contentSize.height+20;




    }
    else
    {
        _tabelView.scrollsToTop = YES;
        _heightcheckview.constant = 195;
        _tblheight.constant = 105;




    }

if (tableView ==   _tblNoti) {


    static NSString *MyIdentifier = @"noticell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];


    // self.tblheight .constant = tableView.contentSize.height;
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:MyIdentifier] ;
    }


    //        FoodDescModalClass *orderDataTypess;
    if(!(self.arrayforNoti.count == 0))
    {
        NSDictionary *diction = [self.arrayforNoti objectAtIndex:indexPath.row];
        UILabel *lbl = (UILabel*)[cell.contentView viewWithTag:2345];
        lbl.text = [diction valueForKey:@"data"];
    }
    return cell;

}

else if (tableView ==   _tabelView){

    static NSString *MyIdentifier = @"maineecell";

    CollTableViewCell *cells = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];


    // self.tblheight .constant = tableView.contentSize.height;
    if (cells == nil)
    {
        cells = [[CollTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                         reuseIdentifier:MyIdentifier] ;
    }



    if(_havecomment)
    {

        if(indexPath.row == self.arrayforitems.count)
        {


            UITableViewCell* celld = [tableView dequeueReusableCellWithIdentifier:@"commentcell"];
            UILabel *lblcomment = [celld.contentView viewWithTag:4545];
            lblcomment.text = _finalcomment;
            lblcomment.layer.borderWidth = 1.0f ;
            lblcomment.layer.cornerRadius = 4.0f ;
            lblcomment.layer.masksToBounds = YES;

            return celld;

        }else{
            NSDictionary*dict = [self.arrayforitems objectAtIndex:indexPath.row];


            cells.lblName.text=  [dict valueForKey:@"item"];
            cells.lblPrice.text = [dict valueForKey:@"price"];
            cells.lblquantity.text = [dict valueForKey:@"qty"];

            NSString*type = [dict valueForKey:@"type"];

            if([type isEqualToString:@"1"])
            {
                cells.imgveg.image=[UIImage imageNamed:@"veg"];
            }
            else if([type isEqualToString:@"2"])
            {
                cells.imgveg.image=[UIImage imageNamed:@"nonveg"];

            }

            else
            {
                cells.imgveg.image=[UIImage imageNamed:@"drink.png"];

            }


            cells.lblquantity.layer.borderWidth = 1.0f ;
            cells.lblquantity.layer.cornerRadius = 4.0f ;
            cells.lblquantity.layer.masksToBounds = YES;
        }




    }
    else{
        NSDictionary*dict = [self.arrayforitems objectAtIndex:indexPath.row];


        cells.lblName.text=  [dict valueForKey:@"item"];
        cells.lblPrice.text = [dict valueForKey:@"price"];
        cells.lblquantity.text = [dict valueForKey:@"qty"];

        NSString*type = [dict valueForKey:@"type"];

        if([type isEqualToString:@"1"])
        {
            cells.imgveg.image=[UIImage imageNamed:@"veg"];
        }
        else if([type isEqualToString:@"2"])
        {
            cells.imgveg.image=[UIImage imageNamed:@"nonveg"];

        }

        else
        {
            cells.imgveg.image=[UIImage imageNamed:@"drink.png"];

        }


        cells.lblquantity.layer.borderWidth = 1.0f ;
        cells.lblquantity.layer.cornerRadius = 4.0f ;
        cells.lblquantity.layer.masksToBounds = YES;
    }

    return cells;
}



else
{



    return nil;
}}

屏幕截图位于

之下

按顺序进行

  1. http://prntscr.com/du4p2f
  2. http://prntscr.com/du4p00
  3. http://prntscr.com/du4q1t

0 个答案:

没有答案