加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

更改细节公开按钮的图像(Xcode 4.2)

发布时间:2020-12-14 17:56:15 所属栏目:百科 来源:网络整理
导读:我已经使用以下建议的例程来更改表视图单元格中的详细信息公开按钮图像(在tableView cellForRowAtIndexPath中) if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; UIButton *myAccessor
我已经使用以下建议的例程来更改表视图单元格中的详细信息公开按钮图像(在tableView cellForRowAtIndexPath中)

if (cell == nil) {

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

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

但是,单击按钮时,现在不再调用事件tableView accessoryButtonTappedForRowWithIndexPath.

谁有任何想法为什么?

解决方法

我已经给了弗莱的答案1,但只是从其他网站提取代码以使其更加完整:答案是你必须自己设备上配置.呼叫将不会自动生成,因为它将建立 – 详细信息披露,所以你必须自己使用按钮的目标.

从链接代码转换到上面的示例,在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,并调用表视图通常会调用的方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读