Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I wrote a UITableView.
I put a Button in the Cell, by clicking on the Button to determine the height of the Cell, and then hidden at the bottom of the UIview.
Now the situation is.
I click on the Button, the height of the Cell has changed, but the following Cell not to catch up with him. How to make it do this?
Thank you first for my answer.



C#
<pre lang="C#">The following is the code I wrote.</pre>



<pre lang="objc">
@implementation SeventyTwoHoursViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor grayColor];
    
}

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

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


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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SeventyTwoCellTableViewCell *cell = [SeventyTwoCellTableViewCell setUpSeventyTwoCell:tableView];
    
    return cell;
    
}

@end


Objective-C
@implementation SeventyTwoCellTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    self.bottomView.backgroundColor = [UIColor redColor];
    
}

- (void)click {
    UIImage *image = [UIImage imageNamed:@"weather_72h_Pull_icon"];
    CGRect rect = self.frame;
    if ([self.btn.currentImage isEqual:image]) {
        [self.btn setImage:[UIImage imageNamed:@"weather_72h_drop_down_icon"] forState:UIControlStateNormal];
        self.bottomView.hidden = YES;
        rect.size.height = 150;
        self.frame = rect;
    }
    else {
        [self.btn setImage:[UIImage imageNamed:@"weather_72h_Pull_icon"] forState:UIControlStateNormal];
        self.bottomView.hidden = NO;
        rect.size.height = 236;
        self.frame = rect;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

+ (instancetype)setUpSeventyTwoCell:(UITableView *)tableview {
    static NSString *ID = @"SeventyTwoHousCell";
    SeventyTwoCellTableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"SeventyTwoCellTableViewCell" owner:nil options:nil] lastObject];
    }
    return cell;
}
- (void)setFrame:(CGRect)frame {
 
    if ((frame.size.width = [UIScreen mainScreen].bounds.size.width)) {
        frame.size.width  -= 20;
    }
    
    if (!frame.origin.x) {
       frame.origin.x += 10;
    }
    
    if (!frame.origin.y) {
        frame.origin.y += 10;
    }
    
    [super setFrame:frame];
}
@end


What I have tried:

About the height of the UITableViewCell does not automatically refresh in ios.
Posted
Comments
xiaoyizhou 21-Jul-16 17:45pm    
@implementation SeventyTwoHoursViewController


- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor grayColor];

}

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

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


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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SeventyTwoCellTableViewCell *cell = [SeventyTwoCellTableViewCell setUpSeventyTwoCell:tableView];

return cell;

}

@end
Surya_Narayan 27-Jul-16 7:06am    
very Poor answer. did understand what he was asking..
Surya_Narayan 27-Jul-16 7:05am    
what is your structure of your TableViewCell ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900