0

I have been spending the past two days trying to figure out this issue, so any information or thoughts on why this is happening is appreciated.

So my problem is, when I add a button to my view controller in the interface builder and create the normal ibaction code the button performs as it should, I then drag and drop from the button to a view controller to create a segue, this works fine as well.

The issue comes in when I run the app, the app will run fine until I push the button(note: I still have the basic skeleton for the button inaction but I do not have it running any code, it is completely blank) that goes to the segue, when I push the button it stops the app and gives this error message

    2013-09-12 08:43:17.696 MessAround[51565:c07] -[UIButton text]: unrecognized selector sent to instance 0xa1cb6c0
2013-09-12 08:43:17.699 MessAround[51565:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton text]: unrecognized selector sent to instance 0xa1cb6c0'
*** First throw call stack:
(0x1d09012 0x11ede7e 0x1d944bd 0x1cf8bbc 0x1cf894e 0x3ac0 0x57cac7 0x57cb54 0x1201705 0x138920 0x1388b8 0x1f9671 0x1f9bcf 0x1f8d38 0x16833f 0x168552 0x1463aa 0x137cf8 0x1f42df9 0x1f42ad0 0x1c7ebf5 0x1c7e962 0x1cafbb6 0x1caef44 0x1caee1b 0x1f417e3 0x1f41668 0x13565c 0x22bd 0x21e5)
libc++abi.dylib: terminate called throwing an exception

Doesn't matter how many buttons I add to this view they give this error, I can however add a button to any of my other views and make a segue to this view and it works perfectly.

Thanks in advance for any thoughts

Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
Maccle415
  • 222
  • 4
  • 13
  • Where in the code does this crash happen? If you don't already have, add an exception breakpoint: http://stackoverflow.com/questions/4961770/run-stop-on-objective-c-exception-in-xcode-4 – nikolovski Sep 12 '13 at 07:14
  • have you check currently..? i think you did mistake at setting text of Button title or setting IBAction of Button programeticuly. might there you did some mistake. – Nitin Gohel Sep 12 '13 at 07:15

3 Answers3

3

Ok so I found what the issue was, I didn't even realise that the button I had made was calling the prepareForSegue method, in that method I had used data from the sender, but the button did not supply the correct data so it broke.

Here is the problem code :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    urlToPurchase = [NSString stringWithFormat:@"%@",[sender text]];

    if([[segue identifier] isEqualToString:@"PurchaseDomain"])
    {        
        PurchaseView *pv = [segue destinationViewController];
        pv.urls = _urls;
        pv.domainIsAvailable = domainIsAvailable;
        pv.tld = _tld;
        pv.chosenDomain = urlToPurchase;
    }

}

and this is the working code :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    /*
      urlToPurchase = [NSString stringWithFormat:@"%@",[sender text]]; Needs to be
      moved to be inside the if statement below
    */

    if([[segue identifier] isEqualToString:@"PurchaseDomain"])
    {        
        //been moved to here
        urlToPurchase = [NSString stringWithFormat:@"%@",[sender text]];

        PurchaseView *pv = [segue destinationViewController];
        pv.urls = _urls;
        pv.domainIsAvailable = domainIsAvailable;
        pv.tld = _tld;
        pv.chosenDomain = urlToPurchase;
    }
}

Thanks a lot all especially @Eiko for trying to help me!

Maccle415
  • 222
  • 4
  • 13
0

Check your button reference Outlet connection on your ViewController.

Besi
  • 22,579
  • 24
  • 131
  • 223
Aarumugam
  • 11
  • 4
0

The answer is right in that exception: You are calling text on a UIButton, and a UIButton doesn't have that property.

There's also a slight chance that you wired it up wrongly in your IB file to something that actually should have a text method.

Eiko
  • 25,601
  • 15
  • 56
  • 71
  • Can that property be called by dragging and drop the link for the segue? – Maccle415 Sep 12 '13 at 08:38
  • What are you trying to do? You typically access properties in code to check or set their value. – Eiko Sep 12 '13 at 08:42
  • I am just making a button to go back to the first view controller(this is created by adding the button in the IB and then dragging from the button to the view I need to go to and selecting the push action, this is how I done it with all my other button too), I am not wanting to send any data to that view at all, I have many other buttons in my app that use segues with no issue. I do not know where I would be trying to access the UIButton text property, I am changing the text property int the storyboard I have no UIButton code change things on the button. I am so confused, I am new to ios – Maccle415 Sep 12 '13 at 08:55
  • Ok I have just done that, it only returns results for text boxes and cell label text, I also searched for UIButton but no results were found, and I have deleted all IBActions from that button, the button works, it is just when I add a segue to it then it gives that error – Maccle415 Sep 12 '13 at 09:05
  • Is there any code running on that segue? Something *does* call text on one button or another... Maybe what you think is wired up to a text box is wired up to a button? – Eiko Sep 12 '13 at 09:15
  • There is some code to get a value from a text box, and it works fine if I create a button from another to the main view(the one that breaks in previous comments), but I will check the text and see how things are wired up, if I don't use that button the app works fine. I have also tried making a UIAlertView button go to the view controller I need it to go to but that breaks as well. Thanks a lot for the help, much appreciated! – Maccle415 Sep 12 '13 at 09:27