Expand UITableView cell in UITableViewstylePlain

前端 未结 7 2067
北荒
北荒 2020-12-13 16:20

I want to expand tableview cell on it\'s click. There is a tableview in which two cells are expandable and others are not. I need when i click on expandable cell it should s

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 16:44

    Okay, what I'm thinking is, The titles, Events, Overhead and Friends would be the custom UIView with UIImageView for background, UILabel for title, and UIButton for expand. So basically

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    

    having return count of the titles you've.

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    

    having return UIView for each titles.

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

    having count of the rows within that title. You may need to maintain an array for this.

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

    having height of the cell item

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    

    initially it should be 0 (zero) for all sections, when user tap on expand, it should be increase with respect to number of rows * cell height within that section.

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

    You may need some good logic for setting all rows for expansion

    Your expansion buttons actions something like,

    - (void) expandSection:(UIButton *)sender;
    

    that you can identify which section to be expand using sender.tag, so don't forget to add tag properly. You may need an int in .h file for store the current section, and can be use in - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section datasource method.

提交回复
热议问题