uibutton and title

Discussion in 'iOS Programming' started by sgs1, Dec 16, 2014.

  1. sgs1 macrumors newbie

    Joined:
    Jul 14, 2014
    #1
    Hello!

    I need to get the title of a button, but i see only "Button" when i execute the function.
    For example: the title of the button is "Test"..and when i press on it , i need to see in my debugging "Test". In the screen of my Ipad i see the button with "Test" title.
    At the moment, i see "Button". What i'm wrong?

    I've wrote it in swift and i paste here the code.

    Code:
    var name = "Test"
    let button = UIButton()
    button.setTitle("\(name)", forState: UIControlState.Normal)
    button.setTitleColor(UIColor.blueColor(), forState: .Normal)
    button.frame = CGRectMake(15, CGFloat(altezza), 300, 700)
    button.addTarget(self, action: "open:", forControlEvents: .TouchUpInside)
    self.view.addSubview(button)
    
    func open(sender:UIButton)
        {
            
            if let text = bottone.currentTitle {
                
                println(" \(text)")
                
            }
            else{ println ("ok") }
            
    
        }
    
    
    
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    The name of the variable you're getting the title from (shown in red above) isn't the button you created earlier.

    Also, you don't seem to understand the purpose of the sender parameter of your open() function. Here's a question you should know (or be able to find) the answer to:
    Since you set the open() function as the button's target for actions, what should the sender parameter be when the button action is triggered?
     
  3. sgs1 thread starter macrumors newbie

    Joined:
    Jul 14, 2014
    #3
    Hi and thanks for the reply!
    I post here the code and i'm using comments for explain my problem. Hope that it's clear!
    Code:
     let (resultSet, err) = SD.executeQuery("SELECT Name, remoteUrl FROM thetable")
            if err != nil {
                //there was an error during the query, handle it here
            } else {
            
                for row in resultSet {
                    
                
                    if let name = row["Name"]?.asString() {
                    
                        println("The City name is: \(name)")
                     // Here i need to create a uibutton and when i press on it , i see the website.
                     // For example: if i have 2 urls, i have 2 buttons. In the first button i open first website. Same logic for the second.
    
                    }
                   
            }
    
     

Share This Page