I'm getting a crash when changing the title for a button twice.
Basically my object makes some strings, randomly they are nil or a string.
Before adding the [button setTitle..]; code there were no problems, no memory leaks or anything. Every time I ran the method the label text would change to the new string in the object.
After adding the text, one of 3 things would happen depending on the random order of nil and strings.
run program -> buttonString=nil -> buttonString=nil ... you could do this forever without crashing.
run program -> buttonString = @"something" -> buttonString = nil ... as long as it stays nil now its fine. The text goes to "something" then blank.
run program -> buttonString = @"something" -> buttonString = @"somethingelse" *CRASH*
I don't get it, there is nothing in UIButton's documentation that indicates it the title can only be changed once (or changed to nil after that but not back to a real string).
I could probably make a new button object, and set it to my button object. But I'd rather not have to if there is something I'm missing about the setTitle: instance method.
Code:
// these are @property (retain, nonatomic) UILabel *label;
// and @property (retain, nonatomic) UIButton *button;
// and @property (retain, nonatomic) MyObject *currentObject;
@synthesize label, button, currentObject;
// every time a certain button (not my *button) is pressed it calls this
- (IBAction) makeNewThing {
MyObject *newObject = [[MyObject alloc] initSpecial];
self.currentObject = newObject;
[newObject release];
label.text = currentObject.labelString;
// problem code
[button setTitle: currentObject.buttonString forState: UIControlStateNormal];
Basically my object makes some strings, randomly they are nil or a string.
Before adding the [button setTitle..]; code there were no problems, no memory leaks or anything. Every time I ran the method the label text would change to the new string in the object.
After adding the text, one of 3 things would happen depending on the random order of nil and strings.
run program -> buttonString=nil -> buttonString=nil ... you could do this forever without crashing.
run program -> buttonString = @"something" -> buttonString = nil ... as long as it stays nil now its fine. The text goes to "something" then blank.
run program -> buttonString = @"something" -> buttonString = @"somethingelse" *CRASH*
I don't get it, there is nothing in UIButton's documentation that indicates it the title can only be changed once (or changed to nil after that but not back to a real string).
I could probably make a new button object, and set it to my button object. But I'd rather not have to if there is something I'm missing about the setTitle: instance method.