- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里是业余爱好者。我使用 UISplitViewController 创建了一个 iOS Swift 应用程序。到目前为止效果很好。我希望能够在查看 DetailViewController View 时加载存储在 MasterViewController 中的数据,而无需返回到 MasterViewContoler View 并选择其中显示的 UITableView 中的项目。唷,真是拗口,我希望这是有道理的。这可能吗?我不知道如何继续。这些图像可能会更好地解释:
我已阅读这些问题:getting the MasterViewController from the DetailViewController in a UISplitViewController app和 SplitView - reload data in master tableView based on detail changed in swift但它们并不完全是我想要的。
这是我的 DetailViewController 代码:
import UIKit
import SafariServices
class DetailViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var stackView: UIStackView!
@IBOutlet weak var detailDescriptionLabel: UILabel!
@IBOutlet weak var compareToButton: UIButton!
@IBAction func compareToButtonTapped(_ sender: Any) {
//do something here?
}
@IBOutlet weak var pathologyImageViewOne: UIImageView!
@IBOutlet weak var pathologyImageViewTwo: UIImageView!
@IBOutlet weak var detailUsedLabel: UILabel!
@IBOutlet weak var detailReferenceLabel: UILabel!
@IBOutlet weak var detailPhotoOneCaptionLabel: UILabel!
@IBOutlet weak var detailPhotoTwoCaptionLabel: UILabel!
var caseIDOne = 0
var caseIDTwo = 0
var compareToButtonString = "Hello"
func configureView() {
// Update the user interface for the detail item.
if let detail = detailItem {
if let detailDescriptionLabel = detailDescriptionLabel,
let compareToButton = compareToButton,
let detailUsedLabel = detailUsedLabel,
let pathologyImageViewOne = pathologyImageViewOne,
let pathologyImageViewTwo = pathologyImageViewTwo,
let detailReferenceLabel = detailReferenceLabel,
let detailPhotoOneCaptionLabel = detailPhotoOneCaptionLabel,
let detailPhotoTwoCaptionLabel = detailPhotoTwoCaptionLabel {
title = detail.name
caseIDOne = detail.caseIDOne
caseIDTwo = detail.caseIDTwo!
detailDescriptionLabel.text = detail.description
compareToButtonString = detail.compareTo!
UIView.performWithoutAnimation {
compareToButton.setTitle("\(compareToButtonString)", for: .normal)
}
detailUsedLabel.text = detail.used
detailReferenceLabel.text = detail.reference
pathologyImageViewOne.image = UIImage(named: detail.photoOne)
pathologyImageViewOne.layer.cornerRadius = 4
pathologyImageViewOne.contentMode = .scaleAspectFill
pathologyImageViewOne.clipsToBounds = true
pathologyImageViewTwo.image = UIImage(named: detail.photoTwo!)
pathologyImageViewTwo.layer.cornerRadius = 4
pathologyImageViewTwo.contentMode = .scaleAspectFill
pathologyImageViewTwo.clipsToBounds = true
// The image in the foreground
let frontImage = UIImage(named: "tap-icon")
// Create the view holding the image
let frontImageViewOne = UIImageView(image: frontImage)
// The size and position of the front image
frontImageViewOne.frame = CGRect(x: 0 , y: 0, width: 34, height: 42)
// turn off AutoresingMask
frontImageViewOne.translatesAutoresizingMaskIntoConstraints = false
// change alpha
frontImageViewOne.alpha = 0.8
// Create the view holding the image again
let frontImageViewTwo = UIImageView(image: frontImage)
// The size and position of the front image again
frontImageViewTwo.frame = CGRect(x: 0 , y: 0, width: 34, height: 42)
// turn off AutoresingMask again
frontImageViewTwo.translatesAutoresizingMaskIntoConstraints = false
// change alpha again
frontImageViewTwo.alpha = 0.8
//MARK: Image One
// Add the front image on top of the background
pathologyImageViewOne.addSubview(frontImageViewOne)
NSLayoutConstraint.activate([
//place the tap icon at the bottom right of parent
frontImageViewOne.bottomAnchor.constraint(equalTo: pathologyImageViewOne.bottomAnchor, constant: -10),
frontImageViewOne.centerXAnchor.constraint(equalTo: pathologyImageViewOne.rightAnchor, constant: -24)
])
let tapGestureRecognizerOne = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizerOne:)))
pathologyImageViewOne.isUserInteractionEnabled = true
pathologyImageViewOne.addGestureRecognizer(tapGestureRecognizerOne)
//MARK: Image two
// Add the front image on top of the background
pathologyImageViewTwo.addSubview(frontImageViewTwo)
NSLayoutConstraint.activate([
//place the tap icon at the bottom right of parent
frontImageViewTwo.bottomAnchor.constraint(equalTo: pathologyImageViewTwo.bottomAnchor, constant: -10),
frontImageViewTwo.centerXAnchor.constraint(equalTo: pathologyImageViewTwo.rightAnchor, constant: -24)
])
let tapGestureRecognizerTwo = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizerTwo:)))
pathologyImageViewTwo.isUserInteractionEnabled = true
pathologyImageViewTwo.addGestureRecognizer(tapGestureRecognizerTwo)
detailPhotoOneCaptionLabel.text = detail.photoOneCaption
detailPhotoTwoCaptionLabel.text = detail.photoTwoCaption
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
configureView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.layoutMargins = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
stackView.isLayoutMarginsRelativeArrangement = true
scrollView.addSubview(stackView)
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
stackView.topAnchor.constraint(equalTo: self.scrollView.topAnchor).isActive = true
stackView.bottomAnchor.constraint(equalTo: self.scrollView.bottomAnchor).isActive = true
}
var detailItem: Descriptor? {
didSet {
// Update the view.
configureView()
}
}
func showWebsite(_ whichCase: Int) {
if let url = URL(string: "https://digitalpathology.uct.ac.za/case_detail.php?case_id=\(whichCase)") {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
let vc = SFSafariViewController(url: url, configuration: config)
present(vc, animated: true)
}
}
@objc func imageTapped(tapGestureRecognizerOne: UITapGestureRecognizer)
{
showWebsite(caseIDOne)
print("Image tapped")
print("CaseOne ID = \(caseIDOne)")
}
@objc func imageTapped(tapGestureRecognizerTwo: UITapGestureRecognizer)
{
showWebsite(caseIDTwo)
print("Image tapped")
print("CaseTwo ID = \(caseIDTwo)")
}
}
我编辑的(为了简洁)MasterViewController 代码:
import UIKit
class MasterViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchFooter: SearchFooter!
var detailViewController: DetailViewController? = nil
var descriptors = [Descriptor]()
var filteredDescriptors = [Descriptor]()
let searchController = UISearchController(searchResultsController: nil)
fileprivate var collapseDetailViewController = true
// MARK: - view setup
override func viewDidLoad() {
super.viewDidLoad()
// Setup the Search Controller
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Descriptors"
navigationItem.searchController = searchController
definesPresentationContext = true
//delagate and data source commented out, connected in storyboard
//tableView.delegate = self
//tableView.dataSource = self
// The data
descriptors = [
Descriptor(name:"Friable", description:"Easily crumbled. Said of tissue that readily tears, fragments, or bleeds when gently palpated or manipulated.", photoOne: "Friable", photoOneCaption:"Subacute bacterial edocarditis", used:"Used in relation to – heart valve vegetations, brittle carcinomatous tissue esp. of cervix.", reference: "Ref: DMD", caseIDOne:769),
Descriptor(name:"Hypertrophic / Hypertrophied", description:"An enlarged, overgrown or bulky organ or part, on account of an increase in the size of its cells (compare ‘hyperplastic’).", compareTo: "Hyperplastic", photoOne: "Hypertrophic1", photoOneCaption:"The heart in hypertension", photoTwo: "Hypertrophic2", photoTwoCaption:"The heart in hypertension", used:"Used in relation to – over-exercised muscles or muscular organs such as heart, bladder, stomach.", reference: "Ref: FPMD", caseIDOne:833, caseIDTwo:833),
Descriptor(name:"Hyperplastic", description:"An enlarged or expanded organ or part, on account of an increase in the formation and number of normal cells (compare ‘hypertrophy’). Hyperplastic expansion may be uniform or nodular.", compareTo: "Hypertrophy", photoOne: "Hyperplastic", photoOneCaption:"Hyperplastic gastropathy in Zollinger-Ellison syndrome", used:"Used in relation to - a benign expansion of the prostate, an endo- or epithelium, lymph node, gums or endocrine glands, usually reflecting hyper-stimulation of some cause.", reference: "Ref: MKEDMNAH", caseIDOne:555),]
if let split = splitViewController {
let controllers = split.viewControllers
detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? DetailViewController
}
//splitViewController?.delegate = self as? UISplitViewControllerDelegate
splitViewController?.delegate = self
}
override func viewWillAppear(_ animated: Bool) {
if splitViewController!.isCollapsed {
if let selectionIndexPath = self.tableView.indexPathForSelectedRow {
self.tableView.deselectRow(at: selectionIndexPath, animated: animated)
}
}
//lets sort the array of objects so A comes before Z
descriptors.sort { $0.name.compare($1.name) == .orderedAscending }
self.tableView.reloadData()
super.viewWillAppear(animated)
}
// MARK: - Segues
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
let descriptor: Descriptor
if isFiltering() {
descriptor = filteredDescriptors[indexPath.row]
} else {
descriptor = descriptors[indexPath.row]
}
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = descriptor
collapseDetailViewController = false
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
let backItem = UIBarButtonItem()
backItem.title = "Pathology A-Z"
navigationItem.backBarButtonItem = backItem
}
}
}
// MARK: - Table View
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if isFiltering() {
searchFooter.setIsFilteringToShow(filteredItemCount: filteredDescriptors.count, of: descriptors.count)
return filteredDescriptors.count
}
searchFooter.setNotFiltering()
return descriptors.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let descriptor: Descriptor
if isFiltering() {
descriptor = filteredDescriptors[indexPath.row]
} else {
descriptor = descriptors[indexPath.row]
}
cell.textLabel!.text = descriptor.name
cell.detailTextLabel!.text = descriptor.description
return cell
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return false
}
extension MasterViewController: UISplitViewControllerDelegate {
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
return collapseDetailViewController
}
}
最佳答案
您应该为默认情况准备一个方法。比如说,在 DetailViewController
中声明 detailDefaultItem
并在 configureView()
之前在 viewDidLoad
中分配给 detailItem
code> (只需删除它,因为它已经在 detailItem
的 didSet
中调用):
override func viewDidLoad() {
super.viewDidLoad()
var detailDefaultItem = Descriptor()
// set/configure needed default values in `Descriptor` class or here below
// detailDefaultItem.property = someValue
// ...
detailItem = detailDefaultItem
// configureView()
...
}
关于ios - UISplitViewController : Can DetailViewController load data from MasterVIewController without segueing back?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55845923/
首先,我使用 Storyboard。我的 ViewController 层次结构如下 NavigationController -> SplashScreen -> LoginScreen -> Ma
我有一个 UISplitview Controller (带有主视图和详细 View )。所以,当 detailview加载 viewDidLoad调用名为 [self animateToPositi
好的,所以我有一个主详细信息应用程序,当用户单击某个单元格时,它会在 DetailViewController 中加载网页。问题是,在 iPhone 版本(这是一个通用应用程序)上,我必须单击单元格,
我做了一个 MasterDetailView 应用程序。在 TableView 中,我有员工列表,在 detailView 中,我有一个欢迎屏幕,其中包含员工详细信息和其他详细信息。当我点击任何员工时
我创建了一个 NavigationBar 和 DetailView,但是当我在 tableView 上选择一行时,没有设置 DetailView 的标题。如何设置? 谢谢! 最佳答案 如果您在 UIN
我正在为一个主从应用程序使用苹果模板,我想知道:如果我在 iPad 或任何其他具有常规水平尺寸类的设备上显示内容。当我打开 MasterViewController 时,DetailViewContr
我的代码没有错误,但是细节 Viewcontroller 上的数组没有接收到我通过 segue 发送给它的对象。我知道我的数组充满了对象,因为我可以将它们打印到日志中.我可以在准备转场之前对它们进行计
我有一个 UITableview,我用数据库中的数据填充了它,我知道将什么数据发送到另一个 View (detailViewController),但是我无法让它工作,现在我正在通过 - (void)
我有一个主 TableView 和一个详细 View 。当我单击单元格详细信息 View 时,应显示该项目的详细信息。现在我想做的是创建 subview 并将该 subview 放入详细 View 中
我正在使用 UISplitViewController 开发 iPad 应用程序。我还使用 DetailViewController 在其中显示一些来自 XML 的信息,但是这些信息没有显示在 Det
我很难选择显示为 Split View Controller 中的详细 View 的 View Controller 。似乎在 showDetail 后面有一些 View Controller 的默认
我已经查看了互联网上的每个答案,但它一直给出错误。我知道这可能会重复,但解决方案对我不起作用。 我已将 detailViewController 设为公共(public)类 我添加了 detailVi
我开始使用 Storyboard,但注意到一个非常显着的区别:每次我来回导航时, Storyboard似乎都会实例化一个新的 ViewController。示例:我基于 Master-Detail 模
我正在尝试创建一个 iPad 应用程序,其用户界面与 Apple 的邮件应用程序类似,即: RootView Controller ( TableView )位于 Split View的左侧,用于通过
我正在 iPad 上开发这个应用程序。我的 MainWindow 包含一个 Split View Controller ,它加载 RootViewController 和 DetailViewCont
目前,我有一个带有 MasterViewController 和 DetailViewController 的 SplitViewController。我想知道是否有办法拥有更多 DetailView
因此,使用下面的代码,我将我的 CollectionViewCell indexPath 插入到新的 DetailViewController 中。现在每个“DetailViewController”
我正在尝试创建一个 master-DetailView 应用程序,但目前我陷入困境,我正在尝试为我的数据创建模板。例如,我想要一个数组来手动控制数据(例如标签/图像)并通过索引路径进行更改,因此每个单
我正在我的应用程序中实现 SplitViewController。我的问题是,当我在较小的设备(例如 iphone5)上显示此内容时,我的 SplitViewController 的 masterVi
这个问题已经有答案了: Passing data between view controllers (44 个回答) 已关闭 4 年前。 我的模型中有一个名为 的字典 var detailStock:
我是一名优秀的程序员,十分优秀!