I have a swift app based on Master-Detail
template. Every row in MasterView
table is based on custom cell received from a nib. Every cell includes UIlabel
and UIbutton
. The logic of the app is following. If user taps on a row DetailView
shows some details depending on selected row. The button on the row does not call tableView(_, didSelectRowAtIndexPath)
. If user taps on the button inside a row only an image belongs to DetailView
should be changed (other elements on DetailView
remain the same) but it isn't. If I select another row and than select previous row back, changed image is shown on the DetailView
as it was foreseen. The question is how to redraw the image in the DetailView
just by tapping on the button.
I've tried to do following but with no success:
class MasterViewCell: UITableViewCell {
weak var detailViewController: DetailViewController?
@IBAction func buttonTap(sender: AnyObject) {
//method to set new image
detailViewController!.setNewImage()
detailViewController!.view.setNeedsDisplay()
}
}
class MasterViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "itemCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "Cell")
if let split = self.splitViewController {
let controllers = split.viewControllers
self.detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? DetailViewController
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as? MasterViewCell
cell?.detailView = self.detailViewController
return cell!
}