Help - Я застрял в Objective-C / iOS Purgatory ...
ISSUE : Когда я присваиваю значения переменным экземпляра, которые могут передавать значения между полученными контроллерами представления "дополнительные данные XML "(т.е. - данные-призраки).Пожалуйста, смотрите скриншот ниже.
Я думаю, что это утечка памяти.Ваши мысли?
Снимок экрана с результатами:
Вот код:
-(void)parserDidEndDocument:(NSXMLParser *)parser
{
itemNotFound = [[NewItemViewController alloc]
initWithNibName:@"NewItemViewController"
bundle:nil];
itemFound = [[ItemViewController alloc]
initWithNibName:@"ItemViewController"
bundle:nil];
// If # of items from Google API request equals zero, then go to User Generated Item Screen
if ( totalResults == @"0") {
[self.view addSubview:itemNotFound.view];
} else {
[self.view addSubview:itemFound.view];
}
[totalResults release];
totalResults = nil;
// Added 7-13-2011: Assign UPC code to a variable to use in Item View
NSString *upcItem = [[NSString alloc]
initWithString:itemNumber];
NSString *titleItem = [[NSString alloc]
initWithString:itemDesc];
NSString *brandItem = [[NSString alloc]
initWithString:itemBrand];
NSString *storeItem = [[NSString alloc]
initWithString:itemStore];
NSString *imageItem = [[NSString alloc]
initWithString:[itemImagesArray objectAtIndex:0]];
self.itemFound.upcScanned = upcItem;
self.itemFound.titleScanned = titleItem;
self.itemFound.brandScanned = brandItem;
self.itemFound.storeScanned = storeItem;
self.itemFound.imageScanned = imageItem;
NSLog(@"RetainedUPC = %@", self.itemFound.upcScanned);
NSLog(@"RetainedTitle = %@", self.itemFound.titleScanned);
NSLog(@"RetainedBrand = %@", self.itemFound.brandScanned);
NSLog(@"RetainedStore = %@", self.itemFound.storeScanned);
NSLog(@"RetainedImage = %@", self.itemFound.imageScanned);
}
Остаток кода файла реализации, связанный с синтаксическим анализом XML:
// This delegate method will inform the application of new elements and collect the associated strings
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
// totalResults is a counter to determine if the item was found on the Google Search API
if ([elementName isEqual:@"openSearch:totalResults"]) {
NSLog(@"found totalResults!");
if (!totalResults)
totalResults = [[NSMutableString alloc] init];
return;
}
//********** test to ensure Product Element is found ********/
/*
if ([elementName isEqual:@"s:product"]) {
NSLog(@"found Product!");
if (!productScanned)
productScanned = [[NSMutableArray alloc] init];
return;
}*/
//******* EOF: test to ensure Product Element is found ******/
if ([elementName isEqual:@"s:gtin"]) {
// set ItemNumber as the GTIN of the productScanned
itemNumber = [[NSMutableString alloc] init];
}
if ([elementName isEqual:@"s:title"]) {
// set ItemDesc as the item description of the productScanned
itemDesc = [[NSMutableString alloc] init];
}
if ([elementName isEqual:@"s:brand"]) {
// set ItemBrand as the brand description of the productScanned
itemBrand = [[NSMutableString alloc] init];
}
if ([elementName isEqual:@"s:name"]) {
// set ItemStore as the store location of the productScanned
itemStore = [[NSMutableString alloc] init];
}
// Create array of Image Tags
if ([elementName isEqual:@"s:images"]) {
NSLog(@"found Images!");
if (!itemImageURLArray)
itemImageURLArray = [[NSMutableArray alloc] init];
return;
}
if ([elementName isEqual:@"s:image"]) {
// itemImagesArray is an NSMutableArray instance variable
if (!itemImagesArray)
itemImagesArray = [[NSMutableArray alloc] init];
NSString *thisLink = [attributeDict objectForKey:@"link"];
if (thisLink)
// do something
[itemImagesArray addObject:thisLink];
return;
}
}
// This method appends item information to the text objects on the view
- (void)parser:(NSXMLParser *)parser
foundCharacters:(NSString *)string
{
[totalResults appendString:string];
[itemNumber appendString:string];
[itemDesc appendString:string];
[itemBrand appendString:string];
[itemStore appendString:string];
}
// Take the text found in each element and add the final string to itemDetails
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
// totalResults is a counter to determine if the item was found on the Google Search API
if ([elementName isEqual:@"openSearch:totalResults"]) {
NSLog(@"ended totalResults: %@", totalResults);
}
if ([elementName isEqual:@"s:gtin"]) {
NSLog(@"ended gtin: %@", itemNumber);
[itemDetails addObject:itemNumber];
//upcField.text = itemNumber;
}
if ([elementName isEqual:@"s:title"]) {
NSLog(@"ended title: %@", itemDesc);
[itemDetails addObject:itemDesc];
//itemField.text = itemDesc;
}
if ([elementName isEqual:@"s:brand"]) {
NSLog(@"ended brand: %@", itemBrand);
[itemDetails addObject:itemBrand];
//brandField.text = itemBrand;
}
if ([elementName isEqual:@"s:name"]) {
NSLog(@"ended store: %@", itemStore);
[itemDetails addObject:itemStore];
//storeField.text = itemStore;
}
if ([elementName isEqual:@"s:image"]) {
NSLog(@"ended image: %@", itemImagesArray);
[itemDetails addObject:itemImagesArray];
}
}
ОБНОВЛЕНИЕ : Основываясь на отзывах от dragon112 , я исправил проблему с "строковым литералом" ...
ИСПРАВЛЕНО: я анализирую вызов Google API.По результатам я хотел бы загрузить один из двух контроллеров представления.Если «итоговые результаты» = 0, загрузите «NewItemVC», иначе загрузите «ItemVC».