Reputation: 365
Pretty straight forward; just trying to change the display name of my button from "Button" to "a." But the setTitle method doesn't seem to do anything. I played around with the UIState, and that didn't seem to change much.
Do I maybe need to synthesize anything?
[Button1 setTitle:@"a" forState:UIControlStateNormal];
EDIT: I did an NSLog, and the button is showing as NULL, which I've been told means it isn't connected properly. But I double-checked my Connections Inspector, looked at the H file, and everything seems to link up fine. (http://imgur.com/EFsp51U) What am I missing?
Upvotes: 1
Views: 4689
Reputation: 13020
Do the following:
Do
NSLog(@"%@", Button1);
and check that it's not nil.
Check that
NSLog(@"%d", btn.state);
should return 0.
Upvotes: 0
Reputation: 365
I went digging through my code, and in my viewDidLoad method, I had the following:
Button1 = NO;
I think I was trying to type out "selected" but got distracted and didn't come back to it, and so was inadvertently turning my own button off. The correct code is:
self.Button1.selected=NO;
[self.Button1 setTitle:@"a" forState:UIControlStateNormal];
Upvotes: 2
Reputation: 750
If you haven't explicitly synthesized it then you should be calling either
[_Button1 setTitle:@"a" forState:UIControlStateNormal];
or
[self.Button1 setTitle:@"a" forState:UIControlStateNormal];
Upvotes: 0
Reputation: 1208
Make sure you have synthesized your Button.
//this assumes you have a button "myButton" declared in your interface file
@implementation
@synthesize myButton;
-(void) myMethod{
[myButton setTitle:@"The new Title" forState:UIControlStateNormal];
}
@end
You should have your button connected through IB outlets to your .h file or create the button entirely through code.
Also it is good practice to not have variable names beginning with a capital letter.
Upvotes: 0
Reputation: 8066
Your code is perfectly valid. But just to make sure everything is ok, add following extra line,
Button1.selected = NO;
[Button1 setTitle:@"a" forState:UIControlStateNormal];
Upvotes: 0
Reputation: 2352
If you have created your button in Interface Builder, then go there and change its type to custom.
And also check if you have connected your IBOutlet
correctly.
Upvotes: 6
Reputation: 2727
I'm not sure that the problem is about thread but you may want to try to set the title on main thread:
dispatch_async(dispatch_get_main_queue(), ^{
[Button1 setTitle:@"a" forState:UIControlStateNormal];
});
Upvotes: 0