Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sgs1

macrumors newbie
Original poster
Jul 14, 2014
28
0
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") }
        

    }
 
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 = [COLOR="Red"]bottone[/COLOR].currentTitle {
            
            println(" \(text)")
            
        }
        else{ println ("ok") }
        

    }

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?
 
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?

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.

                }
               
        }
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.