开发者

NSArray does not update its data second time I try to access it

开发者 https://www.devze.com 2022-12-11 01:42 出处:网络
I am making a call to a web service, the results of the web service are in a form of a string, separated by delimiters.the result string is 1|101|Y|103|Y|105|Y|107|Y|109|Y|112|N|114|N|116|Y|

I am making a call to a web service, the results of the web service are in a form of a string, separated by delimiters.the result string is 1|101|Y|103|Y|105|Y|107|Y|109|Y|112|N|114|N|116|Y|

Now I tokenize the result string, the first token is 1, and based on this value I display the next menu.

If I do an invalid log in the result is Error

and now second time if I enter the correct user name and password, the first token has a value of Error1.

How am I to get rid of the results obtained in case of invalid log in? My loginController.m file is

 -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"return"])
{

    recordResults = FALSE;
    **NSArray *chunks=[soapResults componentsSeparatedByString:@"|"];**

    NSLog(soapResult);
    NSLog([chunks objectAtIndex:0]);//Second time on correct login, it displays in console as Error1

    if([[chunks objectAtIndex:0] isEqualToString:@"1"])
    {

        Menu *mv2 = [[Menu alloc] initWithNibName:@"Menu" bundle:nil];
        testAppDelegate *appdel=(testAppDelegate *)[[UIApplication sharedApplication]delegate];
        appdel.soapResult=self.soapResult;
        self.mv1=mv2;
        NSLog(appdel.soapResult);
        [self presentModalViewController:mv1 animated:YES];
        [mv1 release];

    }else {
        //[[chunks objectAtIndex:0] setText:@""];


        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Sorry Invalid Login"
                                                     delegate:self cancelButto开发者_开发百科nTitle:@"OK" otherButtonTitles: nil];

        [alert show];
        [alert release];


        username_TextField.text=@"";
        password_TextField.text=@"";
            }


}

}

- (void)dealloc 
{
[username_TextField release];
[password_TextField release];
[chunks release];
[super dealloc];

}


This is pretty difficult for me to follow but, let me get this straight:- The first time you -startElement you create an NSMutableString 'soapResults'. Every time you -foundCharacters you append them onto 'soapResults'. Every time you -endElement you parse the ever growing 'soapResults'?

Do you really want to only create one 'soapResults' and keep adding on to it?

0

精彩评论

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