-4

我是 iOS 开发的新手,我有一个自定义表格视图,上面放置了 3 个按钮,

  1. 添加评论
  2. 向上箭头
  3. 向下箭头

我想在按下向下箭头按钮时增加单元格的高度,还要使添加评论按钮,向下箭头按钮可见。

我的代码,

#import "JCoutGoingConfess.h"

@interface JCoutGoingConfess (private)
- (BOOL)cellIsSelected:(NSIndexPath *)indexPath;
@end

@implementation JCoutGoingConfess
#define kCellHeight 132.0

@synthesize outConfessionNavbarBAckBtn,JCoutGoingTbl;

//---------------------------- TableView---------------------------------------
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths
              withRowAnimation:(UITableViewRowAnimation)animation
{
    NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:1 inSection:0];
    NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    // If our cell is selected, return double height
    if([self cellIsSelected:indexPath]) {
        return kCellHeight * 2.0;
    }
    return kCellHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                            reuseIdentifier:CellIdentifier];
    }
    // ----------------------- cellbackground image-----------------------------
    if([self cellIsSelected:indexPath]){
        cell.backgroundView =[[UIImageView alloc]initWithFrame:CGRectMake(160, 151, 320, 108)];
        cell.backgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"inCellFullBg.png"]];
    }
    //         ********   imageView on cell    *******
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(112,0, 90, 90)];
    imgView.image = [UIImage imageNamed:@"friendsfacepic.png"];
    [cell.contentView addSubview:imgView];

    //----------------------------Cell buttons-------------------------------------------
    if (JcOutCellSize==152)
    {

        UIButton *AddComment = [UIButton buttonWithType:UIButtonTypeCustom];
        [AddComment addTarget:self
                       action:@selector(TestBtns:)
             forControlEvents:UIControlEventTouchDown];

        AddComment.frame = CGRectMake(9.0, 128.0, 96.0, 26.0);
        [cell.contentView addSubview:AddComment];

        UIImage *buttonAddComment = [UIImage imageNamed:@"addcomment.png"];
        [AddComment setBackgroundImage:buttonAddComment forState:UIControlStateNormal];
        [cell.contentView addSubview:AddComment];

        UIButton *UpArrow = [UIButton buttonWithType:UIButtonTypeCustom];
        [UpArrow addTarget:self
                    action:@selector(ResizeCell:)
          forControlEvents:UIControlEventTouchDown];
        //[DownArrow setTitle:@"Arrow" forState:UIControlStateNormal];
        UpArrow.frame = CGRectMake(143.0, 136.0, 26.0, 16.0);
        [cell.contentView addSubview:UpArrow];

        UIImage *buttonUp = [UIImage imageNamed:@"upArrow.png"];
        [UpArrow setBackgroundImage:buttonUp forState:UIControlStateNormal];
        [cell.contentView addSubview:UpArrow];
    }

    //----------------------------------------------------------------------------------
    if (JcOutCellSize==132)
    {
        NSLog(@" down arrow %f",JcOutCellSize);
        UIButton *DownArrow = [UIButton buttonWithType:UIButtonTypeCustom];
        [DownArrow addTarget:self
                      action:@selector(IncreseCellHight:)
            forControlEvents:UIControlEventTouchDown];
        DownArrow.frame = CGRectMake(143.0, 116.0, 26.0, 16.0);
        [cell.contentView addSubview:DownArrow];

        UIImage *buttondown = [UIImage imageNamed:@"upDownArrow.png"];
        [DownArrow setBackgroundImage:buttondown forState:UIControlStateNormal];
        [cell.contentView addSubview:DownArrow];
        NSLog(@" cell size = %f",JcOutCellSize);
    }




-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:TRUE];
    // Toggle 'selected' state
    BOOL isSelected = ![self cellIsSelected:indexPath];
    NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
    [selectedIndexes setObject:selectedIndex forKey:indexPath];
    [JCoutGoingTbl beginUpdates];
    [JCoutGoingTbl endUpdates];
}



- (void)viewDidLoad
{
    selectedIndexes = [[NSMutableDictionary alloc] init];
    [super viewDidLoad];
}


- (void)viewDidUnload
{
    selectedIndexes = nil;
    [super viewDidUnload];
}

- (BOOL)cellIsSelected:(NSIndexPath *)indexPath {
    // Return whether the cell at the specified index path is selected or not
    NSNumber *selectedIndex = [selectedIndexes objectForKey:indexPath];
    return selectedIndex == nil ? FALSE : [selectedIndex boolValue];
}

这没有按预期工作,可能是什么问题?

4

1 回答 1

-1

在按钮操作中设置任何整数变量值并将条件放入heightForRowAtIndexPath,无论您想要什么大小,然后重新加载表

于 2013-09-06T09:40:13.313 回答