세 개의 UILabels이 있습니다. 어떤 레이블이 Tapped인지 을 감지하고 해당 레이블의 문자열 값을 검색하고 싶습니다. 이것은 내가 시도하는 방법이며 탭 위치를 감지 할 수만 있었지만 어떤 라벨이 탭되었는지 감지 할 수 없었습니다.어떤 UILabel을 탭했는지 감지하는 방법은 무엇입니까?
라벨 작성
for (NSInteger i=1; i<=[pdfs count]; i++){
UILabel *newLabel=[[UILabel alloc] init];
newLabel.text = [NSString stringWithFormat:[[pdfs objectAtIndex:(i-1)] lastPathComponent]];
newLabel.frame = CGRectMake(10, 60*i, 320, 20);
newLabel.tag=i;
newLabel.font = [UIFont systemFontOfSize:20.0f];
newLabel.backgroundColor = [UIColor clearColor];
newLabel.userInteractionEnabled = YES;
[self.view addSubview:newLabel];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[newLabel addGestureRecognizer:singleTap];
[newLabel release], newLabel=nil;
[singleTap release];
}
감지 도청
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
CGPoint location;
location = [recognizer locationInView:self.view];
NSString *documentName;
if(location.y<150.0){
documentName = [[pdfs objectAtIndex:0] lastPathComponent];
}
else{
documentName = [[pdfs objectAtIndex:1] lastPathComponent];
}
시간이 걸렸 습니다만 ... –
고마워요, – sajaz