New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When the PopupViewContreller dismissed,the UITableViewController which presented it,ran reloadData() didn't work #72
Comments
Hi! Sorry for the late response, have been really busy with work, but I'm taking this whole week to look over all the issues and PR's. I just want to understand your problem a little bit better. So it does work when you call DispatchQueue.main.async { self.tableView.reloadData() } But not when you call self.tableView.reloadData() Or are you trying to say that the table reloading sometimes works and sometimes doesn't? |
Thanks for the response! What I'm trying to say is that after you called |
Oh ok. Well if you're calling reloadData on a table view and those two methods are not being called that means that the releadData is not working. Is your delegate/data-source everything setup correctly? Can you share your code in text-form so I can look over it maybe see what's going on. |
There's no reason for calling it on the main queue since the Presentr delegate is called on the main queue. |
MainTableViewController.swiftimport Foundation
import UIKit
import Presentr
let DLWUserDefaults = UserDefaults.standard
let SWidth = UIScreen.main.bounds.width
let SHeight = UIScreen.main.bounds.height
let topController = UIApplication.shared.keyWindow?.rootViewController
let mainS = MainTableViewController.shareInstance
class MainTableViewController:UITableViewController{
static let shareInstance = MainTableViewController()
let MainSB = UIStoryboard.init(name: "Main", bundle: nil)
let presenter:Presentr = {
let width = ModalSize.full
let height = ModalSize.fluid(percentage: 0.4)
let center = ModalCenterPosition.customOrigin(origin: CGPoint.init(x: 0, y: SHeight/9))
let presenter = Presentr.init(presentationType: .custom(width: width, height: height, center: center))
presenter.transitionType = TransitionType.coverVerticalWithSpring
presenter.dismissTransitionType = TransitionType.coverVerticalFromTop
return presenter
}()
lazy var popupViewController: PopupViewController = {
let popupViewController:PopupViewController = self.MainSB.instantiateViewController(withIdentifier: "Popup") as! PopupViewController
// popupViewController.delegate = self
popupViewController.timeResponse = {(backStr:String)->Void in
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
return popupViewController
}()
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "baseCell") as! mineCell;
cell.presenter = self.presenter
cell.selfController = self
return cell
}
} PopupViewController.swiftimport Foundation
import UIKit
import Presentr
typealias TimeReturn = (_ selectTime:String)->Void
class PopupViewController:UIViewController {
var timeResponse:TimeReturn?
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension PopupViewController:PresentrDelegate {
func presentrShouldDismiss(keyboardShowing: Bool) -> Bool {
print("Dismissing View Controller")
self.timeResponse!("123454")
return !keyboardShowing
}
} mineCell.swiftimport Foundation
import UIKit
import Presentr
class mineCell: UITableViewCell {
var selfController:MainTableViewController?
var presenter:Presentr?
@IBOutlet weak var popBtn: UIButton!
@IBAction func popBtn_clicked(_ sender: AnyObject) {
selfController!.customPresentViewController(selfController!.presenter, viewController: mainS.popupViewController, animated: true) {
}
}
} Podfile
|
Thanks for all the info! This looks like it's a problem with your app code, for some reason the table is not reloading. I would have architected the app a little differently but nothing stands out as me, it should be working, it should be reloading the table. I will close this issue since this is outside Presentr, BUT if you can/want to submit a zip file with this sample code so I can run it I might help you track down the source of your problem. |
Checked your e-mail, fixed your problem!
Scratched my head a little bit but ultimately realized the problem. You had a static property like so: static let main = MainTableViewController() Which honestly is a wrong architecture solution, BUT anyways, the problem is that inside your 'mineCell' you were using the static MainTableViewController, which is a different instance than the one created by you by the interface builder. So you were calling reloadData on a different instance (of the same class) of the view controller, which was calling reloadData, but since there was nothing in view since that view controller is not in view, then cellForRowAtIndexPath is not being called. Removed the static property, and added a couple of log messages to test everything, and it seems everything is working correctly. Check your email! Thanks. |
I finally aware of what I did wrong, I thought the static MainTableViewController and the one created by the |
No worries! :) |
Here's my PopupViewController and how I use it in my UITableViewController.
Usually,when
DispatchQueue.main.async { self.tableView.reloadData() }
worked,the method "cellForRowAtIndexPath" would ran as the nextstep.But when PopupViewController dismissed,the "reloadData()" ran but "cellForRowAtIndexPath" didn't react, so that the tableView cannot refresh immediately.
The text was updated successfully, but these errors were encountered: