gpt4 book ai didi

xcode - 更改详细信息披露按钮的图像(Xcode 4.2)

转载 作者:行者123 更新时间:2023-12-05 00:36:47 26 4
gpt4 key购买 nike

我已使用以下建议例程更改表格 View 单元格中的详细信息披露按钮图像(在 tableView cellForRowAtIndexPath 中)

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

UIButton *myAccessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
[myAccessoryButton setBackgroundColor:[UIColor clearColor]];
[myAccessoryButton setImage:[UIImage imageNamed:@"ball"] forState:UIControlStateNormal];
[cell setAccessoryView:myAccessoryButton];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

然而,事件 tableView accessoryButtonTappedForRowWithIndexPath现在不再在单击按钮时调用。

有没有人知道为什么?

最佳答案

我已经对 Fry 的回答进行了 +1,但只是为了从其他站点提取代码以使其更加完整:答案是您必须使用附件按钮Tapped .... 调用不会像它那样自动进行内置详细信息披露,因此您必须自己使用按钮的目标来完成。

将链接代码转换为上面的示例,在 setImage 之后添加以下行:

[myAccessoryButton addTarget:self action:@selector(accessoryButtonTapped:event:)  forControlEvents:UIControlEventTouchUpInside];

然后稍后添加:
- (void)accessoryButtonTapped:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil) {
[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}

(从 this link 逐字复制)

请注意,这假定按钮是在 UITableViewController 中创建的(在我的情况下,我在自定义单元格中创建一个,因此引用略有不同)

说明:accessoryButtonTapped 是我们自定义按钮的自定义目标方法。当按钮被按下时(“TouchUpInside”),然后我们找到按下发生点的单元格的 indexPath,并调用表格 View 通常会调用的方法。

关于xcode - 更改详细信息披露按钮的图像(Xcode 4.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7797843/

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