我在表格的每個單元格中都有3個UILabels。我已經爲每個人添加了點擊手勢識別器,但是當它被點擊時,我怎樣才能獲取被點擊的行的索引路徑?如何在UITableView中獲取UILabel動作?
這裏是我的代碼
UILabel *tit_lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,10,280,45)];
[tit_lbl setText:[[final_dictionaires_array objectAtIndex:indexPath.row] objectForKey:title]];
[tit_lbl setUserInteractionEnabled:YES];
[tit_lbl setTag:indexPath.row];
[btn addSubview:tit_lbl];
[tit_lbl release];
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToArticleDetailsView:)];
[tit_lbl addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
有了這個,我可以得到標籤行動,但我想被點擊哪一行哪個標籤? (每行有3個標籤)。
這裏是我的代碼UILabel * tit_lbl = [[UILabel alloc] initWithFrame:CGRectMake(10,10,280,45)]; [tit_lbl setText:[[final_dictionaires_array objectAtIndex:indexPath.row] objectForKey:title]]; [tit_lbl setUserInteractionEnabled:YES]; [tit_lbl setTag:indexPath.row]; [btn addSubview:tit_lbl]; [tit_lbl release]; UITapGestureRecognizer * tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToArticleDetailsView :)]; [tit_lbl addGestureRecognizer:tapRecognizer]; [tapRecognizer發佈]; – 2012-01-13 12:20:52
爲什麼不使用UIButtons自定義樣式? – Novarg 2012-01-13 12:41:47