How do i change the temporaryDateVariable properly?
Have tried nested If-statements, if else statements and so on.
What i want to do is for the IBaction tha开发者_如何学编程t is called under three different buttons to change the temporaryDateVariable so that the different buttons send different data so that i can collect different data under the -(void)parser:parserDidEndDocument
delegate method
-(IBAction)sendXmlData:(id)sender {
if([self button1pressed]){
temporaryDateVariable = date1Variable
}
if([self button2pressed]) {
temporaryDateVariable = date2Variable
}
if([self button3pressed]) {
temporaryDateVariable = date3Variable
}
NSString *postString = [[NSString alloc] initWithFormat:@"<xml-string>",temporaryDateVariable]
//lots of nsxmlparserstuff, that is working.
}
The result out of this is that the last date always prevails.
Edit: I resolved this issue by assigning tag variables to each of the three buttons, and the problem had nothing to do with the postString
by assigning tag variables to all of the buttons.
So by doing this.
-(void)viewDidLoad{
button1.tag = x;
button2.tag = y;
button3.tag = z;
}
-(IBAction)sendXmlData:(id)sender {
switch ( ((UIButton *)sender).tag ) {
case x:
temporaryDateVariable = date1Variable;
break;
case y:
temporaryDateVariable = date2Variable;
}
// same old same old
}
It actually works.
精彩评论