0

我想在滑动 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 意味着删除发件人。我能做些什么?

4

2 回答 2

1

该错误抱怨名为holdpress. 在您发布的代码中,您有一个名为holdpress:. 注意区别 - 方法有一个冒号,而错误方法没有。

同样在您发布的代码中,您将手势识别器设置为使用holdpress:. 这与您实际拥有的方法正确匹配。那是对的。

由于错误是 aboutholdpress而不是holdpress:,您必须有一些其他代码尝试使用holdpress选择器而不是holdpress:.

贴出的代码是从哪里来的PhotoViewController

在您的代码中搜索对holdpress(not holdpress:) 的调用。

于 2013-01-22T18:22:24.770 回答
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];
}}
于 2013-01-22T18:34:40.490 回答