Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CustomCell类中的UIPangestureRecognitor stateEnded通知MainViewController_Ios_Objective C_Uitableview - Fatal编程技术网

Ios CustomCell类中的UIPangestureRecognitor stateEnded通知MainViewController

Ios CustomCell类中的UIPangestureRecognitor stateEnded通知MainViewController,ios,objective-c,uitableview,Ios,Objective C,Uitableview,My apps MainViewController将UITableView与CustomCell中的自定义UITableViewCells一起使用。使用UIPangestureRecognitor,用户可以向左或向右滑动单元格。幻灯片结束后,textLabel.text和幻灯片方向存储为静态字符串 动画代码是CustomCell,工作正常 当CustomCell的识别器.state==UIgestureRecognitizerStateEnded时,MainViewController如何知道

My apps MainViewController将UITableView与CustomCell中的自定义UITableViewCells一起使用。使用UIPangestureRecognitor,用户可以向左或向右滑动单元格。幻灯片结束后,textLabel.text和幻灯片方向存储为静态字符串

动画代码是CustomCell,工作正常

当CustomCell的识别器.state==UIgestureRecognitizerStateEnded时,MainViewController如何知道或得到通知? 定制单元

主视图控制器

完成后,我计划使用CustomCell中的2个静态字符串执行从MainViewController到另一个ViewController的模式转换。我只需要幻灯片操作后的2个字符串。

添加此代码

UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

[self addGestureRecognizer:recognizer];
在MainViewController中创建单元后,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];

     //more of your existing code here

     UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

     [self addGestureRecognizer:recognizer];
     return cell;
}
并将handlePan:方法移动到MainViewController


除非有充分的理由让您在cell类中使用handlePan:方法,否则如果您不想创建/设置委托或使用块,最好将其添加到MainViewController中

我已经尝试过了。这是一个很大的改变,并将作为最后的结果。另外,这不允许tableview再滚动,为什么?您能否更深入地了解使用委托或块的细节。关于设置委托,在UITableViewCell上设置委托,有很多很好的答案。这里有一个例子,你已经讲了很长时间了。如果你能对你的问题使用正确的格式,这会对每个人都有帮助——类似于我编辑的方式。
UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

[self addGestureRecognizer:recognizer];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];

     //more of your existing code here

     UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

     [self addGestureRecognizer:recognizer];
     return cell;
}