简体   繁体   中英

how to make accordion in ios with image

I would like to ask on how to hide the image in accordion using UITableView? First I create tableview and delegate it. here is the code of my viewcontroller

#import "ViewController.h"
#import "ListViewCell.h"
@interface ViewController (){
    NSArray * tableData;
    NSInteger currentSelection;
    int one;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    one = 0;
    // Do any additional setup after loading the view, typically from a nib.
    tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
}

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


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

    return [tableData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"mycell";

    ListViewCell *cell = (ListViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {

        [tableView registerNib:[UINib nibWithNibName:@"listxib" bundle:nil] forCellReuseIdentifier:@"mycell"];
        cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    }
     cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([indexPath row] == currentSelection && one !=0) {
        return  312;
    }
    else return 75;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    currentSelection = [indexPath row];

    if(one==1){
        NSLog(@"%@",@"active");
        one = 0; // check if this is active


    }else{
       NSLog(@"%@",@"not active");
        one =1;
    }


    [tableView beginUpdates];
    [tableView endUpdates];
}

I have no problems displaying text on the label in the cell. I create xib file to inherit it to my tableview cell and the name of the UITableviewCell controller is ListViewCell. see my image bellow

在此处输入图片说明

when I used that xib and display to my UITableview i get this result 在此处输入图片说明

I you see the image. The big image of that girl overlap the UITableView. It supposed to be hide, it will only diplay when user click the cell and expand the height of cell. I try to find it in google but they don't have tutorial that using xib file. I enable the AUTOLAYOUT in my setting. Does autolayout matters when doing an accordion with xib? I always think thank this autolayout makes me sick when doing project like this. hoping you understand what I want to do. But if you have tutorial out there. That will be super duper nice to see it.

尝试在单元xib文件中选择大图像视图,选择属性,然后将剪辑打勾到子视图。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM