开发者

Calling NSXMLParser with different variables depending on which button is pressed

开发者 https://www.devze.com 2023-02-20 00:44 出处:网络
How do i change the temporaryDateVariable properly? Have tried nested If-statements, if else statements and so on.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消