No se puede copiar el valor de la matriz mutable en una cadena

i really appreciate for immediate reply and i submit my xml parser methods to you and at last problem is mention.

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
 currentElement = [elementName copy];
 if([elementName isEqualToString:@"alluser"])
 {
  objUser = [[Users alloc] init];
 }
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{
 if([elementName isEqualToString:@"username"])
 {
  objUser.userName =[currentElementValue       stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

  NSLog(@"%@",objUser.userName);
 }
 if([elementName isEqualToString:@"password"])
 {
  objUser.passWord = [currentElementValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSLog(@"%@",objUser.passWord);
 }
 if([elementName isEqualToString:@"user"])
 {
  [usersArray addObject:objUser];


  [objUser release];
 }

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
 if(!currentElementValue) 
 {
  currentElementValue = [[NSMutableString alloc] initWithString:string];
     [currentElementValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
 }
 else
 {
  [currentElementValue appendString:string];
     [currentElementValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
 }

    if([currentElementValue isEqualToString:@"User"])
 { 
  [currentuser appendString:string]; 

 }
 if([currentElementValue isEqualToString:@"Pass"])
 { 
  [currentpass appendString:string]; 

 } 


} 

-(IBAction)backgroundclick:(id)sender
{
 [txtpass resignFirstResponder];
 [txtusername resignFirstResponder];

}


-(IBAction)returnPressed:(id)sender
{
 [sender resignFirstResponder]; 
}



-(IBAction)LoginClicked:(id)sender
{
 int cnt=0;

 NSString *currUser = txtusername.text;
// NSString *passWord = txtpass.text;

// int i=0;
 for(Users *objUser in usersArray )
 {
     /// how to get value and how to compare string... 
 } 
  return; 

}

my mutable array is in this code is (usersArray). i got parse data into the array and i want to check username and password with textfields value if it match with array the certain action is performed. but somehow i cant access data into the string.

preguntado el 08 de enero de 11 a las 17:01

dude, please format your code with the {} option in the editor. -

Please format your post for better code readability. It will help those who are willing to help you. :) -

In future please take the time to format your code correctly and at least check for rudimentary spelling mistakes. If you can't be bothered to spend time asking a question, why would you expect people to bother answering it? -

1 Respuestas

You don't give much detail as to what the problem is, so just guessing... For your loop in LoginClicked() you can compare using:

[currUser isEqualToString:objUser.userName]

Or any other string comparison method. But maybe your problem is something else? In your "parser:didStartElement..." method did you mean to check for the "user" element rather than "allUser"? As it is you allocate only one Users object but attempt to parse many and insert them into an array.

Respondido el 08 de enero de 11 a las 22:01

first of all thank's for you immediate reply and i already try for same thing. the objUser.userName contains all objects string. - Sam007

If you mean your NSLog statements then they will show each user, but its not showing you what you probably think it is. Your didStartElement method allocates Digital XNUMXk Users object, you then parse x >= 0 <user> tags into this Digital XNUMXk object, add that object x times to an array and release it x times. If x is more than 1 you are overwriting the same object (logic error) and releasing it too many times (memory error). - CRD

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.