![](/img/trans.png)
[英]How to open a view controller on click of hyperlink on UILabel in Objective-C
[英]how to use segue table view controller cell click and cell long click in Objective-C
我是Objective-C的新程序員。
我在應用中使用情節提要。 它包含UITableViewController。
當我單擊它是使用segue的單元格時,轉到下一個視圖控制器。 但是我想使用-(void)onLongPress:(UILongPressGestureRecognizer*)
pGesture並通過使用相同的單元格顯示另一個ViewController。
我的TableView顯示了公司。 我想根據單元格LongClick顯示公司詳細信息。
您需要創建一個UILongPressGestureRecognizer。
然后,您需要將其附加到您想要識別longPress的視圖上。 附加它時,您將定義一個動作選擇器和一個目標。 動作選擇器是一種方法,可在識別手勢時在目標中觸發。
假設您在tableViewController中創建了手勢識別器,並且它也是目標,那么它將看起來像這樣
UILongPressGestureRecognizer* longPGR =
[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(onLongPress:)];
[self.relevantViewInTableViewCell addGestureRecognizer:longPGR];
然后創建一個動作方法來攔截水龍頭
-(void)onLongPress:(UILongPressGestureRecognizer*)pGesture
{
//statement
}
如果要使用動態單元格創建表,則在創建單元格時應進行longPGR創建。
如果您有靜態單元格,則可以使IBOutlet @properties連接到有關的單元格,並在longPGR創建中使用該屬性。
要顯示另一個viewController,沒有必要使用segue。 您可以使用longPress方法將新的viewController推送到NavigationController的堆棧上:
[self.navigationController pushViewController:newViewController];
與使用segue具有相同的效果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.