質問

Just like CSS's overflow: none;, how can I hide the out-of-boundary part of UITableViewCell? and show certain components in cell only when it is selected?

I was thinking hiding & showing the elements using UITableViewDelegate methods, but I can't work it out quite well. I used the followings:

NSIndexPath  *selected_index;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  selected_index = indexPath;
  [cell.web_view setHidden:NO];
  [tableView beginUpdates];
  [tableView endUpdates];
}

- (CGFloat)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section) {
  if(selected_index != nil && selected_index.row == indexPath.row) {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestCell"];
    [cell.web_view setHidden:NO];
    return 250;
  }
  [cell.web_view setHidden:YES];
  return 74;
}

where cell.web_view is a UIWebView which has height (200) larger than the table cell (74). But the codes didn't make the web view shows up & hide properly.

What can I do alternatively?

役に立ちましたか?

解決

The closest code for overflow: none is [cell setClipsToBounds:YES];

To hide and show things when tapped you should have a few variables like BOOL shouldShowMyWebViews;, and toggle their state in tableView:didSelectRowAtIndexPath:, and in cellForRowAtIndexPath: you could show or hide your elements just before returning the cell.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top