gpt4 book ai didi

ios - 带有可触摸标签的 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 21:51:05 25 4
gpt4 key购买 nike

我正在尝试创建一个表格 View ,其中的单元格包含姓名、电话和邮件。如果用户触摸电话,应用程序会调用电话(点击调用)。如果用户触摸了邮件,我需要打开邮件应用并向“触摸的地址”发送一封新电子邮件。

首先,我尝试开发包含电子邮件的可触摸标签,但我收到错误消息“选择器已发送到实例”。

我需要识别点击手势,然后识别它是电子邮件还是电话、获取短信和电话或打开邮件应用程序。

当前代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
cell.lblEmail.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)];
[cell.lblEmail addGestureRecognizer:tapGesture];
return cell;
}

- (void)labelTap:(UIGestureRecognizer *)sender {
UILabel *labelSender = (UILabel*) sender;
NSLog(@"%text: %@", labelSender.text);
}

错误:

2015-02-03 12:28:29.726 MyApp[80080:4019203] -[MyAppContactsViewController labelTap]: unrecognized selector sent to instance 0x7ff6d8cb4110
2015-02-03 12:28:29.743 MyApp[80080:4019203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyAppContactsViewController labelTap]: unrecognized selector sent to instance 0x7ff6d8cb4110'
*** First throw call stack:
(
0 CoreFoundation 0x000000010709cf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106d35bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001070a404d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000106ffc27c ___forwarding___ + 988
4 CoreFoundation 0x0000000106ffbe18 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001059912e6 _UIGestureRecognizerSendActions + 262
6 UIKit 0x000000010598ff89 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
7 UIKit 0x0000000105994ba6 ___UIGestureRecognizerUpdate_block_invoke662 + 51
8 UIKit 0x0000000105994aa2 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
9 UIKit 0x000000010598ab1d _UIGestureRecognizerUpdate + 2796
10 UIKit 0x0000000105624ff6 -[UIWindow _sendGesturesForEvent:] + 1041
11 UIKit 0x0000000105625c23 -[UIWindow sendEvent:] + 667
12 UIKit 0x00000001055f29b1 -[UIApplication sendEvent:] + 246
13 UIKit 0x00000001055ffa7d _UIApplicationHandleEventFromQueueEvent + 17370
14 UIKit 0x00000001055db103 _UIApplicationHandleEventQueue + 1961
15 CoreFoundation 0x0000000106fd2551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x0000000106fc841d __CFRunLoopDoSources0 + 269
17 CoreFoundation 0x0000000106fc7a54 __CFRunLoopRun + 868
18 CoreFoundation 0x0000000106fc7486 CFRunLoopRunSpecific + 470
19 GraphicsServices 0x0000000109fa59f0 GSEventRunModal + 161
20 UIKit 0x00000001055de420 UIApplicationMain + 1282
21 MyApp 0x00000001040769a3 main + 115
22 libdyld.dylib 0x0000000107a9c145 start + 1
23 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

改变这一行:

[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)];

[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap:)];

这是必需的,因为作为 选择器labelTaplabelTap: 不同。前者是一个没有参数的选择器(它不存在,因此是异常(exception)),而后者是一个有 1 个参数的选择器,您确实已经定义了它。

关于ios - 带有可触摸标签的 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28301622/

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