我发现这两个UIPageViewControllerDataSource方法存在一个奇怪的问题:第一次进入页面视图控制器场景并拖动控制器的内容时,无论拖动方向是什么,都会调用两个数据源方法.我想当我在第一页并向右拖动时,这意味着在第一页之前没有更多的页面,这两种方法都不应该被调用.如果我向左拖动,只应调用after方法.
我按照这篇文章来设置视图控制器(除了我在故事板上没有单独的页面视图控制器.我使用传统[UIPAgeViewController alloc] init]方法来实例化控制器).以下是我的代码:
对于实际显示页面视图控制器内容的视图控制器(仅显示相关部分viewDidLoad):
- (void)viewDidLoad
{
// initialize page view controller
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
// set up the initial scene of the page view controller
UIViewController *viewController = [self viewControllerAtIndex:0];
[self.pageViewController setViewControllers:@[viewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
// adjust the size of the page view controller, -44 to show the buttons at the bottom
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 44); …Run Code Online (Sandbox Code Playgroud) 关于正常路径操作函数、依赖项和 SQLAlchemy 的菜鸟问题def。引用此处的示例: https: //fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency,其中数据库会话在(同步)中创建get_db()并在create_user()(同步)中使用。根据https://fastapi.tiangolo.com/async/#very-technical-details,同步依赖项和路径操作函数是在线程池中执行的,这是否意味着同一个数据库会话对象在2个不同的线程之间有效共享(假设它不是跨依赖项和路径操作函数重用的同一个线程)?由于 SQLAlchemy 会话不是线程安全的,这会不会有问题?
我可能完全误解了它是如何工作的,所以任何澄清将不胜感激。
谢谢!
编辑:经过更多思考后,我认为这应该没问题,因为会话是按顺序访问的(不是同时访问的),即使它可能由两个不同的线程访问。但我假设使用session类似以下内容会有问题吗?
async def func(s: Session):
loop = asyncio.get_running_loop()
await loop.run_in_executor(None, some_func, s)
await loop.run_in_executor(None, some_other_func, s)
...
Run Code Online (Sandbox Code Playgroud) 我有一个UITextView,用户可以在其中输入一些注释并保存.我想在用户拖动键盘边缘并将其拉下时解除键盘(就像在Message中一样).我在故事板中看到 - >属性检查器 - >滚动视图 - >键盘,有一个下拉菜单,我可以选择解除键盘的方式.我已经尝试了交互式拖拽和解雇,但没有任何反应.我已经尝试将管理文本视图的视图控制器设置为委托,但似乎没有一种方法可以通过它与键盘进行交互.任何的想法?