05-16-2011, 06:50 AM
#1 (permalink )
Registered Member
Join Date: May 2011
Posts: 19
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!
05-16-2011, 07:08 AM
#2 (permalink )
iOSDeveloperz
Join Date: Apr 2011
Location: INDIA
Posts: 99
Quote:
Originally Posted by
s7162
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!
05-16-2011, 07:16 AM
#3 (permalink )
Registered Member
Join Date: May 2011
Posts: 19
Quote:
Originally Posted by
iOSDeveloperz
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'
05-16-2011, 07:18 AM
#4 (permalink )
iOSDeveloperz
Join Date: Apr 2011
Location: INDIA
Posts: 99
Quote:
Originally Posted by
s7162
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
05-16-2011, 07:19 AM
#5 (permalink )
Registered Member
Join Date: Feb 2011
Location: Mobile World
Posts: 450
do like this
Code:
NSString *temp=@"Random";
if ([temp isEqualToString:randomViewButton.titleLabel]){
//something
}
__________________
Thank & Regard
NI3(Not Impossible 3)
05-16-2011, 07:26 AM
#6 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
Code:
if ([randomViewButton.titleLabel.text isEqualToString:@"Random"]){
//something
}
Quote:
Originally Posted by
ngaikwad
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
__________________
05-16-2011, 07:33 AM
#7 (permalink )
Registered Member
Join Date: May 2011
Posts: 19
Quote:
Originally Posted by
iOSDeveloperz
try to use
Code:
randomViewButton.title
this doesnt work either unfortunately
05-16-2011, 07:33 AM
#8 (permalink )
Registered Member
Join Date: Feb 2011
Location: Mobile World
Posts: 450
Quote:
Originally Posted by
dany_dev
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)
05-16-2011, 07:41 AM
#9 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
Quote:
Originally Posted by
s7162
this doesnt work either unfortunately
if you read my first post there is the motive and the solution...
__________________
05-16-2011, 07:47 AM
#10 (permalink )
Registered Member
Join Date: May 2011
Posts: 19
Quote:
Originally Posted by
dany_dev
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
05-16-2011, 07:48 AM
#11 (permalink )
iOSDeveloperz
Join Date: Apr 2011
Location: INDIA
Posts: 99
Quote:
Originally Posted by
s7162
this doesnt work either unfortunately
try dany's code
Code:
randomButton.titleLabel.text
05-16-2011, 07:49 AM
#12 (permalink )
Registered Member
Join Date: Feb 2011
Location: Mobile World
Posts: 450
Quote:
Originally Posted by
s7162
Hi, i tried that, but the app crashed when the ibaction was used
what message on console
__________________
Thank & Regard
NI3(Not Impossible 3)
05-16-2011, 07:54 AM
#13 (permalink )
Registered Member
Join Date: May 2011
Posts: 19
Quote:
Originally Posted by
ngaikwad
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
05-16-2011, 07:55 AM
#14 (permalink )
Registered Member
Join Date: Feb 2011
Location: Mobile World
Posts: 450
Quote:
Originally Posted by
s7162
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)
05-16-2011, 08:53 AM
#15 (permalink )
Registered Member
Join Date: May 2011
Posts: 19
Quote:
Originally Posted by
ngaikwad
dude u r give breakpoint there remove that it will work fine......
huh? sorry, i dont quite understand
05-16-2011, 08:58 AM
#16 (permalink )
Registered Member
Join Date: Nov 2010
Posts: 1,106
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
05-16-2011, 09:07 AM
#17 (permalink )
Registered Member
Join Date: May 2011
Posts: 19
Quote:
Originally Posted by
Meredi86
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
05-16-2011, 10:15 AM
#18 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
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)
__________________
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44