我为摇动手势提供的以下代码工作得非常好,只是当我在三个单独的 uitableviews 中使用它时,一旦你离开一个 tableview 转到下一个,摇动手势就不再起作用了。知道如何让它在所有三个视图控制器上工作吗?另外,我可以选择在“detailviewcontroller”上发布信息,但是,一旦您离开其中一个表格视图,它就会禁用 twitter 的键盘。关于如何解决这个问题的任何想法?谢谢!
//BEGIN SHAKE GESTURE CODE
- (void)viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake) {
int section = 0;
int row = arc4random() %36;
NSIndexPath * path = [NSIndexPath indexPathForRow:row inSection:section];
[self handleSelectedRow:path.row];
[self.tableView selectRowAtIndexPath:path animated:YES scrollPosition: UITableViewScrollPositionNone];
}
}
-(void)handleSelectedRow:(int)row;
{
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tag = row;
[self performSegueWithIdentifier:@"showRecipeDetail" sender:btn];
}
//END SHAKE GESTURE CODE