asked    Jane     2018-10-22       ios       23 view        1 Answer

[SOLVED] Downcasting Any? to UIBarButtonItem

override func prepare(for segue: UIStoryboardSegue, sender:
        Any?) {
    if segue.identifier == "detailSegue" {
        let indexPath = tableView.indexPathForSelectedRow!
        let card = cards[indexPath.row]
        let detailTableViewController = segue.destination as! DetailTableViewController
        detailTableViewController.card = card
        detailTableViewController.picture = card.image
    } else if segue.identifier == "addEditSegue" {
        let addEditTableViewController = segue.destination as! AddEditTableViewController
        let buttonPressed = sender as? UIBarButtonItem
        if buttonPressed == cardsAddButton {
            addEditTableViewController.isNewCard = true
        } else {
            addEditTableViewController.isNewCard = false

Hi, I am new to Swift. I need to perform the same segue by either tapping a UIBarButtonItem (cardsAddButton) or by tapping on cells of a UITableView. Using print statements I found that buttonPressed is nil when I tap cardsAddButton. Why? How should I check what was the sender?

  1 Answer  

        answered    Thera     2018-10-22      

You – the developer – should know who the sender of prepare(for is. There are only three possibilities:

  1. If the segue is connected to the table view cell in Interface Builder then the sender is the UITableViewCell.
  2. If the segue is connected to the view controller in Interface Builder then the sender is the UIViewController.
  3. If performSegue is called in code then the sender is whatever you passed in the sender parameter (including nil).

Your code can work only if you call performSegue in the IBAction of the button and pass the button instance as sender

@IBAction func addCard(_ sender : UIBarButtonItem)
    self.performSegue(withIdentifier:"addEditSegue", sender: sender)

Your Answer

 2018-10-22         Riva

RenderBody with jQuery Ajax calls

I'm think that I'm doing something wrong here in .Net Core. I have layout with @RenderBody Problem is - I'm doing jQuery Ajax calls, my Actions returning me Partial Views. That works good. Problem is, I don't see any path of Controller and Action in URL, can't refresh page, I am returned to the Home. Another problem with Partials Views I can't solve is - Scripts:I can include all scripts in Layout, but some partials views requiring 2-3 scripts, another partials views different 2-3 scripts. I can't split usage, I don't want to throw all in one layout.Can't add them in the Pa...
 c#                     1 answers                     96 view
 2018-10-22         Calvin

c# Count rows in DataTable where all values of row equal to 1

I have a datatable in which the columns and rows are created at runtime, so as a result the column names may vary and row numbers too. Values for each cell can only be 1 or 0.I may get a datatable with say for example 3 columns. e.g.Age | Sex | Location-------------------1 | 0 | 1-------------------0 | 1 | 0--------------------1 | 1 | 1--------------------0 | 1 | 0--------------------1 | 1 | 1--------------------I want to be able to count only the rows which contain 1 on each column. So above example would return 2. Iterate through the rows and column...
 c#                     1 answers                     101 view
 2018-10-22         Darren

How to pass string in the url as a parameter for core api

I am trying to build an api that will take a IForm file from the body and save the file. Then return the filename in the directory. I have worked with the same structure before. But then I had an integer value in the parameter now it is a string. I am trying this way. But when the route matches it always returning status 200 without saving the file and filename in the respond. [HttpPost][Route("/api/users/${email}/photos")]public async Task<IActionResult> Upload(string email, [FromBody]IFormFile fileStream){ var user = this.repository.GetUserByEmail(email); if (...
 c#                     1 answers                     102 view