[ad_1]
I’ve a tableView displaying a number of duties already created by the person. When the person click on on a activity (tableView cell) i need to current a pop-up displaying extra data in regards to the person’s activity. I already created the popUp view and it is displaying positive however the knowledge (class, date, hour) will not be displaying contained in the popUp. I do not know the best way to entry my knowledge and put it into the pop-up View when the person click on on the row. Here is what i attempted to this point :
MyTasksCollectionCell
class MyTasksCollectionCell: UICollectionViewCell, UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath) as! MyTasksTableCell
cell.accessoryType = .disclosureIndicator
let activity = {() -> Add in
change (displayedTask) {
case .present:
// First phase tapped
return self.duties[indexPath.row]
case previous:
// Second phase tapped
return self.pastTasks[indexPath.row]
}
}()
cell.categoryLabel.textual content =
"(activity.class)"
cell.dateLabel.textual content =
"(activity.date)"
cell.hourLabel.textual content =
"(activity.hour)"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let activity = {() -> Add in
change (displayedTask) {
case .present:
// First phase tapped
return self.duties[indexPath.row]
case previous:
// Second phase tapped
return self.pastTasks[indexPath.row]
}
}()
let selectedCell = tableView.cellForRow(at: indexPath) as? MyTasksDetailView//Warning message right here !!! "Solid from 'UITableViewCell?' to unrelated kind 'MyTasksDetailView' at all times fails"
selectedCell?.class.textual content = "(activity.class)"
selectedCell?.hour.textual content = "(activity.hour)"
selectedCell?.date.textual content = "(activity.date)"
print (selectedCell?.class.textual content)
let popupView = MyTasksDetailView()
UIApplication.shared.keyWindow?.addSubview(popupView)
}
extension UIApplication {
var keyWindow: UIWindow? {
// Get linked scenes
return UIApplication.shared.connectedScenes
// Maintain solely lively scenes, onscreen and visual to the person
.filter { $0.activationState == .foregroundActive }
// Maintain solely the primary `UIWindowScene`
.first(the place: { $0 is UIWindowScene })
// Get its related home windows
.flatMap({ $0 as? UIWindowScene })?.home windows
// Lastly, maintain solely the important thing window
.first(the place: .isKeyWindow)
}
}
MyTasksDetailView
class MyTasksDetailView: UIView {
var setCategory: String? {
didSet {
categoryLabel.textual content = setCategory ?? ""
}
}
var setDate: String? {
didSet {
dateLabel.textual content = setDate ?? ""
}
}
var setHour: String? {
didSet {
hourLabel.textual content = setHour ?? ""
}
}
let categoryLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont.systemFont(ofSize: 28, weight: .daring)
// label.textual content = "class"
label.textAlignment = .middle
label.textColor = .label
return label
}()
let dateLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont.systemFont(ofSize: 18, weight: .daring)
// label.textual content = "date"
label.textAlignment = .middle
label.numberOfLines = 3
label.textColor = .label
return label
}()
let hourLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont.systemFont(ofSize: 18, weight: .daring)
// label.textual content = "hour"
label.textAlignment = .middle
label.numberOfLines = 3
label.textColor = .label
return label
}()
let container: UIView = {
let v = UIView()
v.translatesAutoresizingMaskIntoConstraints = false
v.clipsToBounds = true
v.backgroundColor = .white
v.layer.cornerRadius = 24
v.backgroundColor =
// 1
UIColor { traitCollection in
// 2
change traitCollection.userInterfaceStyle {
case .darkish:
// 3
v.layer.borderColor = UIColor.label.cgColor
return UIColor.systemBackground
default:
// 4
v.layer.borderColor = UIColor.black.cgColor
return UIColor.systemBackground
}
}
return v
}()
lazy var stack: UIStackView = {
let stack = UIStackView(arrangedSubviews: [categoryLabel, dateLabel, hourLabel])
stack.translatesAutoresizingMaskIntoConstraints = false
stack.axis = .vertical
return stack
}()
@objc func animateOut() {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 1, choices: .curveEaseIn, animations: {
self.container.remodel = CGAffineTransform(translationX: 0, y: -self.body.top)
self.alpha = 0
}) { (full) in
if full {
self.removeFromSuperview()
}
}
}
@objc func animateIn() {
self.container.remodel = CGAffineTransform(translationX: 0, y: -self.body.top)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 1, choices: .curveEaseIn, animations: {
self.container.remodel = .id
self.alpha = 1
})
}
override init(body: CGRect) {
tremendous.init(body: body)
self.addGestureRecognizer(UITapGestureRecognizer(goal: self, motion: #selector(animateOut)))
let blurEffect = UIBlurEffect(model: .darkish)
let blurEffectView = UIVisualEffectView(impact: blurEffect)
blurEffectView.body = bounds
blurEffectView.alpha = 1
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.addSubview(blurEffectView)
self.body = UIScreen.major.bounds
self.addSubview(container)
container.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
container.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
container.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.7).isActive = true
container.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.45).isActive = true
container.addSubview(stack)
stack.leadingAnchor.constraint(equalTo: container.leadingAnchor).isActive = true
stack.trailingAnchor.constraint(equalTo: container.trailingAnchor).isActive = true
stack.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true
stack.heightAnchor.constraint(equalTo: container.heightAnchor, multiplier: 0.5).isActive = true
animateIn()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been carried out")
}
}
[ad_2]
