NSString没有被添加到NSMutableArray

时间:2011-02-23 12:31:59

标签: iphone objective-c

-(IBAction)orderButtonPressed
{       
     myString = staterlabel1.text;
     [myArray addObject:myString];

     NSLog(@"wat is in  %@",myArray);       
}


-(IBAction)orderButton2Pressed
{           
     myString2  = staterlabel2.text;
     [myArray addObject:myString];
     NSLog(@"wat is in  %@",myArray);    
}

点击按钮后,myString中的文字应添加到NSMutableArray对象myArray,但这不会发生。我做错了什么?

1 个答案:

答案 0 :(得分:2)

你有一个错字

(IBAction)orderButtonPressed
{       
     myString = staterlabel1.text;
     [myArray addObject:myString];

     NSLog(@"wat is in  %@",myArray);       
}


-(IBAction)orderButton2Pressed
{           
     myString2  = staterlabel2.text;
     [myArray addObject:myString2]; // <-- change here
     NSLog(@"wat is in  %@",myArray);    
}

在第二种方法中,您需要添加myString2而不是myString