Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-16-2011, 06:50 AM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 19
s7162 is on a distinguished road
Question comparing UIButton title

Hey guys,

i wanna compare the title for a UIButton, but the method im using is clearly wrong, as it isn't working, -

Code:
if ([randomButton.titleLabel isEqual:@"Random"]){
//do something
}
So, my question is, what is the correct method to do this?

thanks!
s7162 is offline   Reply With Quote
Old 05-16-2011, 07:08 AM   #2 (permalink)
iOSDeveloperz
 
iOSDeveloperz's Avatar
 
Join Date: Apr 2011
Location: INDIA
Posts: 99
iOSDeveloperz is on a distinguished road
Send a message via Skype™ to iOSDeveloperz
Default

Quote:
Originally Posted by s7162 View Post
Hey guys,

i wanna compare the title for a UIButton, but the method im using is clearly wrong, as it isn't working, -

Code:
if ([randomButton.titleLabel isEqual:@"Random"]){
//do something
}
So, my question is, what is the correct method to do this?

thanks!
Code:
isEqualToString:
__________________
iOS Developerz
You Think, We Create...

http://iosdeveloperz.com/

View our latest apps
iOSDeveloperz is offline   Reply With Quote
Old 05-16-2011, 07:16 AM   #3 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 19
s7162 is on a distinguished road
Default

Quote:
Originally Posted by iOSDeveloperz View Post
Code:
isEqualToString:
thanks for the reply, heres what i got


Code:
 if ([randomViewButton.titleLabel isEqualToString:@"Random"]){
 //something
}
first i get a warning,

Code:
'UILabel' may not respond to 'isEqualToString'
if i ignore it and run anyways, i get'

Code:
thread 1: program received signal: "SIGBRT"
reason,


*
Code:
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButtonLabel isEqualToString:]: unrecognized selector sent to instance 0x5c41120'
s7162 is offline   Reply With Quote
Old 05-16-2011, 07:18 AM   #4 (permalink)
iOSDeveloperz
 
iOSDeveloperz's Avatar
 
Join Date: Apr 2011
Location: INDIA
Posts: 99
iOSDeveloperz is on a distinguished road
Send a message via Skype™ to iOSDeveloperz
Default

Quote:
Originally Posted by s7162 View Post
thanks for the reply, heres what i got


Code:
 if ([randomViewButton.titleLabel isEqualToString:@"Random"]){
 //something
}
first i get a warning,

Code:
'UILabel' may not respond to 'isEqualToString'
if i ignore it and run anyways, i get'

Code:
thread 1: program received signal: "SIGBRT"
reason,


*
Code:
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButtonLabel isEqualToString:]: unrecognized selector sent to instance 0x5c41120'
try to use
Code:
randomViewButton.title
__________________
iOS Developerz
You Think, We Create...

http://iosdeveloperz.com/

View our latest apps
iOSDeveloperz is offline   Reply With Quote
Old 05-16-2011, 07:19 AM   #5 (permalink)
Registered Member
 
ngaikwad's Avatar
 
Join Date: Feb 2011
Location: Mobile World
Posts: 450
ngaikwad is on a distinguished road
Default

do like this
Code:
NSString *temp=@"Random";
 if ([temp isEqualToString:randomViewButton.titleLabel]){
 //something
}
__________________
Thank & Regard
NI3(Not Impossible 3)
ngaikwad is offline   Reply With Quote
Old 05-16-2011, 07:26 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Code:
 if ([randomViewButton.titleLabel.text isEqualToString:@"Random"]){
 //something
}

Quote:
Originally Posted by ngaikwad View Post
do like this
Code:
NSString *temp=@"Random";
 if ([temp isEqualToString:randomViewButton.titleLabel]){
 //something
}
this will crash for the same motive...you are trying to call isEqualToString with a UILabel
__________________
dany_dev is offline   Reply With Quote
Old 05-16-2011, 07:33 AM   #7 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 19
s7162 is on a distinguished road
Default

Quote:
Originally Posted by iOSDeveloperz View Post
try to use
Code:
randomViewButton.title
this doesnt work either unfortunately
s7162 is offline   Reply With Quote
Old 05-16-2011, 07:33 AM   #8 (permalink)
Registered Member
 
ngaikwad's Avatar
 
Join Date: Feb 2011
Location: Mobile World
Posts: 450
ngaikwad is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
Code:
 if ([randomViewButton.titleLabel.text isEqualToString:@"Random"]){
 //something
}



this will crash for the same motive...you are trying to call isEqualToString with a UILabel
Yes that will right there should be this
randomViewButton.titleLabel.text
__________________
Thank & Regard
NI3(Not Impossible 3)
ngaikwad is offline   Reply With Quote
Old 05-16-2011, 07:41 AM   #9 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by s7162 View Post
this doesnt work either unfortunately
if you read my first post there is the motive and the solution...
__________________
dany_dev is offline   Reply With Quote
Old 05-16-2011, 07:47 AM   #10 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 19
s7162 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
if you read my first post there is the motive and the solution...
Hi, i tried that, but the app crashed when the ibaction was used
s7162 is offline   Reply With Quote
Old 05-16-2011, 07:48 AM   #11 (permalink)
iOSDeveloperz
 
iOSDeveloperz's Avatar
 
Join Date: Apr 2011
Location: INDIA
Posts: 99
iOSDeveloperz is on a distinguished road
Send a message via Skype™ to iOSDeveloperz
Default

Quote:
Originally Posted by s7162 View Post
this doesnt work either unfortunately
try dany's code

Code:
 randomButton.titleLabel.text
__________________
iOS Developerz
You Think, We Create...

http://iosdeveloperz.com/

View our latest apps
iOSDeveloperz is offline   Reply With Quote
Old 05-16-2011, 07:49 AM   #12 (permalink)
Registered Member
 
ngaikwad's Avatar
 
Join Date: Feb 2011
Location: Mobile World
Posts: 450
ngaikwad is on a distinguished road
Default

Quote:
Originally Posted by s7162 View Post
Hi, i tried that, but the app crashed when the ibaction was used
what message on console
__________________
Thank & Regard
NI3(Not Impossible 3)
ngaikwad is offline   Reply With Quote
Old 05-16-2011, 07:54 AM   #13 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 19
s7162 is on a distinguished road
Default

Quote:
Originally Posted by ngaikwad View Post
what message on console
i get the following,,

Code:
thread 1: stopped at breakpoint 2
Code:
Attaching to process 2267.
Pending breakpoint 2 - ""FactsRootViewController.m":29" resolved
Current language:  auto; currently objective-c
s7162 is offline   Reply With Quote
Old 05-16-2011, 07:55 AM   #14 (permalink)
Registered Member
 
ngaikwad's Avatar
 
Join Date: Feb 2011
Location: Mobile World
Posts: 450
ngaikwad is on a distinguished road
Default

Quote:
Originally Posted by s7162 View Post
i get the following,,

Code:
thread 1: stopped at breakpoint 2
Code:
Attaching to process 2267.
Pending breakpoint 2 - ""FactsRootViewController.m":29" resolved
Current language:  auto; currently objective-c
dude u r give breakpoint there remove that it will work fine......
__________________
Thank & Regard
NI3(Not Impossible 3)
ngaikwad is offline   Reply With Quote
Old 05-16-2011, 08:53 AM   #15 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 19
s7162 is on a distinguished road
Default

Quote:
Originally Posted by ngaikwad View Post
dude u r give breakpoint there remove that it will work fine......
huh? sorry, i dont quite understand
s7162 is offline   Reply With Quote
Old 05-16-2011, 08:58 AM   #16 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

look on the left of the screen where the line numbers are. You will see a little blue arrow pointing to your code on the EXACT line that it "crashes" on. Click on that little blue arrow and drag it away as if you were removing it from your dock, then run again. Search for Xcode breakpoints on google if you are still perplexed
Meredi86 is offline   Reply With Quote
Old 05-16-2011, 09:07 AM   #17 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 19
s7162 is on a distinguished road
Default

Quote:
Originally Posted by Meredi86 View Post
look on the left of the screen where the line numbers are. You will see a little blue arrow pointing to your code on the EXACT line that it "crashes" on. Click on that little blue arrow and drag it away as if you were removing it from your dock, then run again. Search for Xcode breakpoints on google if you are still perplexed
brilliant
s7162 is offline   Reply With Quote
Old 05-16-2011, 10:15 AM   #18 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

FYI this is not a crash, is just a breakpoint (a line of code where you decide to pause the running of your code for debugging purpose)
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
button, compare strings, title, uibutton

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
6 members and 355 guests
doffing81, dre, iOS.Lover, Kirkout, MikaelBartlett, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:06 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0