gpt4 book ai didi

objective-c - 在选择时用自定义单元格替换标准 UITableViewCell

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:54:29 25 4
gpt4 key购买 nike

我有一个带有标准 UITableViewCellsUITableview。在选择一个单元格时,我想用自定义单元格替换该单元格,该单元格使用 UITextViews 而不是 detailTextLabelUITextFields 而不是 accessoryView。执行此操作的最佳方法是什么?

最佳答案

创建 UITableViewCell 的子类。将您的 UITextFieldUITextField(以适合您的解决方案为准)添加到 contentView 中,并隐藏它们。覆盖 `-setSelected:animated:' 方法:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if ( animated ) {
// using old-school UIView animation support to fade in/out controls,
// block-based much easier, but only 4.0 or greater
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
self.textLabel.alpha = (selected) ? 0.0 : 1.0;
self.detailTextLabel.alpha = (selected) ? 0.0 : 1.0;
// assumed you added a UITextView 'textView' ivar
self.textView.alpha = (selected) ? 1.0 : 0.0;
[UIView commitAnimations];
}
else {
self.textLabel.hidden = selected;
self.detailTextLabel.hidden = selected;
self.textView.hidden = !selected;
}
}

- (void)animationDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
self.textLabel.hidden = self.selected;
self.detailTextLabel.hidden = self.selected;
self.textView.hidden = !self.selected;
}

关于objective-c - 在选择时用自定义单元格替换标准 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8359344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com