Ok this is a bizarre issue… rather than posting lots of code I will post a few snippets that will explain:
This is a action sheet that I have added a UIDatePicker
in my .h file
NSInteger tagOfDateToUse;
in my .m file I make sure its clear on ViewDidLoad
tagOfDateToUse = 0;
I need this variable because there are multiple text boxes on a screen that could be pulling up this action sheet. So I set this int so that if its a 100 it will go to one text box, if its a 101, it goes to another
I set the tagOfDateToUse in the IBAction. Then in the
(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
… Do some things
It works fine with the 1st one (100) but when I Hit my second button it is 101 up to this point.
As soon as it hits the if tagOfDateToUse is __ it thinks it’s 100 when up to this point it has been 101… what in the if statement is causing it to go back to 100… What am I missing here…
if (tagOfDateToUse = 100) {vacation_starton.text = [[NSString alloc] initWithFormat:@"%@", [formatter stringFromDate:selectedDate]];
}
else if (tagOfDateToUse = 101)
{
vacation_endon.text = [[NSString alloc] initWithFormat:@"%@", [formatter stringFromDate:selectedDate]];
}
Thanks!
You are assigning a value of 100 to tagOfDateToUse which is perfectly legal and then the value is evaluated as a boolean condition in which anything but 0 is true and only 0 is false.
Try changing it to this…