- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我实现了一个 UIPageViewController,允许用户通过单独的 UITableView 添加/删除/删除新的“页面”,类似于 Apple 在 iPhone 天气应用程序中实现城市/天气位置的方式。项目发布如下。此时其中没有天气或花哨的 UI – 我只是想专注于下面的 UIPageViewController 管理。希望如果有人想知道如何使用通过 UITableView 管理的页面来实现 UIPageViewController ,这会很有用: https://github.com/gallaugher/PageViewControllerDemo
它似乎工作正常,但我对此很陌生,并且非常不确定我是否使用推荐的方法或者它是否是“Swifty”来完成此操作。
现在我有:PageViewController [初始 View Controller ]- 将委托(delegate)和数据源设置为自身- 实例化第一个 UIViewController(想象一个用于本地天气的 CityViewController,即使在此示例中未添加详细信息和 UI)并设置初始值。- 城市(天气位置)保存在 [String] 数组中:cityArray
在 CityViewController 中 - 当单击右下角的“城市”按钮(在界面生成器中创建)时,如 Apple Weather,它会打开一个 UITableView (CityListViewController)。
- 为了到达这个 CityListViewController,我触发了一个直接通过界面构建器从 CityViewController 中的“城市”按钮绘制到 CityListViewController 的 Segue,以模态方式呈现。- preapareForSegue 将城市数组传递到 objective-c ityListViewController (UITableView)。
在CityListViewController(UITableView)中- 用户可以在 UITableView 中添加城市、移动、删除更新 tableView 和数组- 单击tableView行(城市名称或“本地天气”)会触发执行segue,展开到CityViewController,获取源CityListViewController并使用它将数据传递回CityViewController(例如citiesArray =controller.citiesArray)。- 这个 @IBAction 展开函数调用 PageViewController 的展开(实际上只是将数据从 CityListViewController 中的 TableView 传递到 UIPageViewController PageViewController)。
在 PageViewController 中放松- 获取源代码(作为 CityViewController)- 传回关键数据(例如cityArray =controller.citiesArray)- 调用函数来实例化当前页面的 View Controller 并设置PageControl索引等。
问题一:虽然这似乎有效并且我在测试期间没有设法打破它,但从 UITableView 展开到 ViewController 是否是一种合理的方法,它只是触发另一个到 UIPageViewController 的展开,除了传递数据之外什么都不做?
第二季度:我通过在 PageViewController 中以编程方式构建 UIPageControl 来实现它,但连接到 CityListViewController(UITableView)的按钮是使用 Interface Builder 在 CityViewController 中创建的。这是正确的方法吗?我似乎无法在同一个 VC 中创建这两个项目。
非常感谢那些有耐心费力解释这个复杂的解释的人。仍在尝试处理 VC 之间的数据传递,以及这与 PageController 和 TableView 的关系。
最佳答案
对于对此感兴趣的解决方案,我已发布到 GitHub: https://github.com/gallaugher/PageViewControllerDemo我发布了更通用的名称 - PageVewController、DetailViewController 和 ListViewController,因此这更容易重用,也许也更容易遵循。
感谢 Sazan Dauti 在 StackOverflow 之外回答这个问题。可以直接在 PageController 和 ListController 之间进行连接,后者包含一个用于管理页面的 TableView 和一组相似的页面(例如,就像 Apple 在天气应用程序中所做的那样,您可以在其中添加/删除/移动城市),保留详细信息(城市中的城市)原始示例)不知道它在 PageView 中。- 将 Segue 直接从 UIPageViewController 拖到具有 TableView 的 UIViewController,在我的例子中,该 TableView 包含位置列表(不是由 PageView 管理的详细信息)。 Segue 应该以模态方式呈现。关键变量应该在 PageViewController 中的准备过程中传递给 ListViewController,如下所示:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ToListViewController" {
let controller = segue.destination as! ListViewController
controller.listArray = listArray
controller.currentPage = currentPage
}
}
确保传递的值(上述情况下的 listArray 和 currentPage)在 ListViewController 中声明。
将 Unwind 方法添加到 PageViewController 中,与此类似:
@IBAction func unwindFromListViewController(sender: UIStoryboardSegue) { pageControl.numberOfPages = listArray.count pageControl.currentPage = 当前Page setViewControllers([createDetailViewController(currentPage)],方向:.forward,动画:false,完成:nil)}
上面的setViewControllers指的是PageViewController中编写的函数,其中包含实例化当前页面的DetailViewController的逻辑。
返回转场是通过从 ListView 中的 TableViewCell 拖动到“退出”按钮(此 UIViewController 顶部/标题 View 的三个按钮的最右侧)来创建的。系统会询问您的名称应该在 PageViewController 中的展开方法(在上面的示例中,我将其称为 unwindFromListViewController),因此请务必在尝试进行转场之前添加此方法。
向ListViewController添加prepare for segue函数:
覆盖函数准备(用于segue:UIStoryboardSegue,发件人:任何?){ if segue.identifier == "ToPageViewController"{ 让controller = segue.destination为!页面 View Controller Controller .currentPage = 当前Page Controller .listArray = listArray }}
并在tableView didSelectRowAt中,触发执行segue:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { currentPage = indexPath.row//将当前页设置为所选行 PerformSegue(withIdentifier:“ToPageViewController”,发件人:self)}
我在网上找不到任何合适的例子来演示这是如何完成的,所以希望这是可以理解和高效的。欢迎任何指正。干杯!
关于swift - 检查方法: Managing UIPageViewController page data using UITableView cells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40616056/
我想了解 Ruby 方法 methods() 是如何工作的。 我尝试使用“ruby 方法”在 Google 上搜索,但这不是我需要的。 我也看过 ruby-doc.org,但我没有找到这种方法。
Test 方法 对指定的字符串执行一个正则表达式搜索,并返回一个 Boolean 值指示是否找到匹配的模式。 object.Test(string) 参数 object 必选项。总是一个
Replace 方法 替换在正则表达式查找中找到的文本。 object.Replace(string1, string2) 参数 object 必选项。总是一个 RegExp 对象的名称。
Raise 方法 生成运行时错误 object.Raise(number, source, description, helpfile, helpcontext) 参数 object 应为
Execute 方法 对指定的字符串执行正则表达式搜索。 object.Execute(string) 参数 object 必选项。总是一个 RegExp 对象的名称。 string
Clear 方法 清除 Err 对象的所有属性设置。 object.Clear object 应为 Err 对象的名称。 说明 在错误处理后,使用 Clear 显式地清除 Err 对象。此
CopyFile 方法 将一个或多个文件从某位置复制到另一位置。 object.CopyFile source, destination[, overwrite] 参数 object 必选
Copy 方法 将指定的文件或文件夹从某位置复制到另一位置。 object.Copy destination[, overwrite] 参数 object 必选项。应为 File 或 F
Close 方法 关闭打开的 TextStream 文件。 object.Close object 应为 TextStream 对象的名称。 说明 下面例子举例说明如何使用 Close 方
BuildPath 方法 向现有路径后添加名称。 object.BuildPath(path, name) 参数 object 必选项。应为 FileSystemObject 对象的名称
GetFolder 方法 返回与指定的路径中某文件夹相应的 Folder 对象。 object.GetFolder(folderspec) 参数 object 必选项。应为 FileSy
GetFileName 方法 返回指定路径(不是指定驱动器路径部分)的最后一个文件或文件夹。 object.GetFileName(pathspec) 参数 object 必选项。应为
GetFile 方法 返回与指定路径中某文件相应的 File 对象。 object.GetFile(filespec) 参数 object 必选项。应为 FileSystemObject
GetExtensionName 方法 返回字符串,该字符串包含路径最后一个组成部分的扩展名。 object.GetExtensionName(path) 参数 object 必选项。应
GetDriveName 方法 返回包含指定路径中驱动器名的字符串。 object.GetDriveName(path) 参数 object 必选项。应为 FileSystemObjec
GetDrive 方法 返回与指定的路径中驱动器相对应的 Drive 对象。 object.GetDrive drivespec 参数 object 必选项。应为 FileSystemO
GetBaseName 方法 返回字符串,其中包含文件的基本名 (不带扩展名), 或者提供的路径说明中的文件夹。 object.GetBaseName(path) 参数 object 必
GetAbsolutePathName 方法 从提供的指定路径中返回完整且含义明确的路径。 object.GetAbsolutePathName(pathspec) 参数 object
FolderExists 方法 如果指定的文件夹存在,则返回 True;否则返回 False。 object.FolderExists(folderspec) 参数 object 必选项
FileExists 方法 如果指定的文件存在返回 True;否则返回 False。 object.FileExists(filespec) 参数 object 必选项。应为 FileS
我是一名优秀的程序员,十分优秀!