[英]how to use segue table view controller cell click and cell long click in Objective-C
I am a new programmer to Objective-C. 我是Objective-C的新程序员。
I use a storyboard in my app. 我在应用中使用情节提要。 It contains UITableViewController.
它包含UITableViewController。
When I click it is cell using segue go to next view controller. 当我单击它是使用segue的单元格时,转到下一个视图控制器。 But I want to use
-(void)onLongPress:(UILongPressGestureRecognizer*)
pGesture and show another ViewController by using the same cell. 但是我想使用
-(void)onLongPress:(UILongPressGestureRecognizer*)
pGesture并通过使用相同的单元格显示另一个ViewController。
My TableView shows Companies. 我的TableView显示了公司。 I want to show company details according to cell LongClick.
我想根据单元格LongClick显示公司详细信息。
You need to create a UILongPressGestureRecognizer. 您需要创建一个UILongPressGestureRecognizer。
Then you need to attach it to the view that you wish to recognise the longPress. 然后,您需要将其附加到您想要识别longPress的视图上。 When you attach it you define an action selector and a target.
附加它时,您将定义一个动作选择器和一个目标。 The action selector is a method that will be trigged in the target when the gesture is recognised.
动作选择器是一种方法,可在识别手势时在目标中触发。
Assuming you create the gesture recogniser in your tableViewController and that is also the target then it would look something like this 假设您在tableViewController中创建了手势识别器,并且它也是目标,那么它将看起来像这样
UILongPressGestureRecognizer* longPGR =
[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(onLongPress:)];
[self.relevantViewInTableViewCell addGestureRecognizer:longPGR];
then you create an action method to intercept the taps 然后创建一个动作方法来拦截水龙头
-(void)onLongPress:(UILongPressGestureRecognizer*)pGesture
{
//statement
}
If you are creating your table with dynamic cells, your longPGR creation should take place when you create the cell. 如果要使用动态单元格创建表,则在创建单元格时应进行longPGR创建。
If you have static cells, you can make IBOutlet @properties connected to the cells concerned, and use that property in your longPGR creation. 如果您有静态单元格,则可以使IBOutlet @properties连接到有关的单元格,并在longPGR创建中使用该属性。
To show the other viewController, it is not necessary to use a segue. 要显示另一个viewController,没有必要使用segue。 You can push the new viewController onto the NavigationController's stack in the longPress method:
您可以使用longPress方法将新的viewController推送到NavigationController的堆栈上:
[self.navigationController pushViewController:newViewController];
That has the same effect as using a segue. 与使用segue具有相同的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.