gpt4 book ai didi

iphone - UIButton 覆盖 UITableViewCell

转载 作者:行者123 更新时间:2023-12-03 18:37:43 31 4
gpt4 key购买 nike

我希望我的表格行之一成为一个按钮,占据 UITableView 的一整行。我认为解决此问题的最佳方法是实例化 UIButton,并为其指定与 UITableViewCell 实例相同的帧大小,并将其作为 subview 添加到单元格中。我已经快到了,但是还差了好几个像素,无法获得完美的触感。有没有更好的方法,或者也许可以修复我的放置精度以获得完美的对齐?

cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [self tableviewCellWithReuseIdentifier:CellIdentifier];
}
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0.0f, 5.0f, 320.0f, 44.0f)];

[button setTitle:@"Do Stuff" forState:UIControlStateNormal];
[button addTarget:self action:@selector(doStuff:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];

最佳答案

您可以在 didSelectRowAtIndexPath: 方法中伪造它。让 tableView 单元格充当按钮。

[[[self tableView] cellForRowAtIndexPath:indexPath] setSelected:YES animated:YES];
[self doStuff];
[[[self tableView] cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES];

使用setSelected:animated:来假装按下按钮并使其淡出。也许能帮到你。

关于iphone - UIButton 覆盖 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/344934/

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