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

更改细节公开按钮的图像(Xcode 4.2),第1张

概述我已经使用以下建议的例程来更改表视图单元格中的详细信息公开按钮图像(在tableView cellForRowAtIndexPath中) if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; UIButt 我已经使用以下建议的例程来更改表视图单元格中的详细信息公开按钮图像(在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,并调用表视图通常会调用的方法.

总结

以上是内存溢出为你收集整理的更改细节公开按钮的图像(Xcode 4.2)全部内容,希望文章能够帮你解决更改细节公开按钮的图像(Xcode 4.2)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1023753.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存