I have a UITextField called txtvwEmail
. i am adding the text from txtvwEmail.text
to the Array pastUrls
but after adding the next text it remove the first text. Im using the code
if (![pastUrls containsObject:txtvwEmail.text]) {开发者_如何学编程
[pastUrls addObject:txtvwEmail.text];
}
You should rely on the basics of the language and frameworks. The array DOES RETAIN the object, however, it could be:
- pastUrls is nil -> no retain
- somewhere in the code .text is released (or autoreleased) and the count is yet the same
Also, you can't really be sure [obj retainCount] return the correct value. To diagnose the real problem, revise the code or post it here so we can help.
//this should be outside of ur all loops
NSMutableArray *pastUrls=[[NSMutableArray alloc]init];
//remove this line
//NSMutableArray *pastUrls=[NSMutableArray array];
if (![pastUrls containsObject:txtvwEmail.text]) {
[pastUrls addObject:txtvwEmail.text];
}
NSLog(@"pastUrls : %@ \n\n",pastUrls);
精彩评论