我希望在打开UItextView时调用方法,并确定其标记。我使用的是这段代码:
-(IBAction)donecomment:(id)sender{
UISwipeGestureRecognizer *myLongPressRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(holdpress:)];
[textname addGestureRecognizer:myLongPressRecognizer];
textname.editable = NO;
textname.userInteractionEnabled = YES;
CGRect frame = textname.frame;
frame.size.height = textname.contentSize.height;
textname.frame = frame;
heightInteger = heightInteger + textname.contentSize.height + 6;
[textnameArray addObject:textname];
addComment.hidden = NO;
doneComment.hidden = YES;
cancelComment.hidden = YES;
}
-(void)holdpress:(id)sender{
UITextView *txtChoosen = (UITextView*) sender;
for (UITextView* txt in textnameArray) {
if (txt.tag == txtChoosen.tag) {
txt.layer.borderWidth = 5.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}else{
txt.layer.borderWidth = 0.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}}
...我收到此错误:原因:' - [PhotoViewController holdpress]:无法识别的选择器发送到实例0x22c1a000'
我想我可以使用以下方法解决它:
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
...但使用htis意味着删除发件人。我该怎么办?
答案 0 :(得分:1)
错误是抱怨名为holdpress
的方法。在您发布的代码中,您有一个名为holdpress:
的方法。注意区别 - 方法有冒号,错误方法没有。
同样在您发布的代码中,您设置了手势识别器以使用holdpress:
的选择器。这与您实际拥有的方法完全匹配。这是对的。
由于错误大约是holdpress
而不是holdpress:
,因此您必须使用其他代码尝试使用holdpress
选择器而不是holdpress:
。
发布的代码来自PhotoViewController
?
在代码中搜索holdpress
(不是holdpress:
)的来电。
答案 1 :(得分:0)
最终解决方案:
-(IBAction)donecomment:(id)sender{
UISwipeGestureRecognizer *myLongPressRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)];
//[myLongPressRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[textname addGestureRecognizer:myLongPressRecognizer];
textname.editable = NO;
textname.userInteractionEnabled = YES;
CGRect frame = textname.frame;
frame.size.height = textname.contentSize.height;
textname.frame = frame;
heightInteger = heightInteger + textname.contentSize.height + 6;
[textnameArray addObject:textname];
addComment.hidden = NO;
doneComment.hidden = YES;
cancelComment.hidden = YES;
}
- (void)leftSwipe:(UISwipeGestureRecognizer *)recognizer {
id sender;
UITextView *txtChoosen = (UITextView*) sender;
for (UITextView* txt in textnameArray) {
if (txt.tag == txtChoosen.tag) {
txt.layer.borderWidth = 5.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}else{
txt.layer.borderWidth = 0.0f;
txt.layer.borderColor = [[UIColor whiteColor] CGColor];
}}