- 내 응용 프로그램 충돌 ramdomly
_storeArray
. - viewDidLoad에서 xml 파일을 구문 분석 한 다음 사전을 추가하는
[self loadUrl]
메서드를 사용합니다.[_storeArray addObject:dictionary]
; - 어떻게 든 회전식 컨베이어 reusingView 처음 호출 후
[self loadUrl]
충돌이 발생합니다. - 나는
if(_storeArray)
을 추가했지만 여전히 충돌이 발생합니다. 이것은 코드NSRangeException 임의로 충돌 응용 프로그램
2013-04-06 09:33:35.254 Semhora[7347:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
:
이는 예외
- (void)loadURL:(NSString *)newURL{
// Create a success block to be called when the asyn request completes
TBXMLSuccessBlock successBlock = ^(TBXML *tbxmlDocument) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// If TBXML found a root node, process element and iterate all children
if (tbxmlDocument.rootXMLElement)
{
// Obtain root element
TBXMLElement * root = tbxml.rootXMLElement;
if (root)
{
[_storeArray removeAllObjects];
TBXMLElement * elem_PLANT = [TBXML childElementNamed:@"principal" parentElement:root];
while (elem_PLANT !=nil)
{
TBXMLElement * elem_title = [TBXML childElementNamed:@"title" parentElement:elem_PLANT];
NSString *titleName = [TBXML textForElement:elem_title];
// TBXMLElement * elem_artist = [TBXML childElementNamed:@"text" parentElement:elem_PLANT];
// NSString *artistName = [TBXML textForElement:elem_artist];
TBXMLElement * elem_thumb = [TBXML childElementNamed:@"thumb_url" parentElement:elem_PLANT];
NSString *thumbName = [TBXML textForElement:elem_thumb];
TBXMLElement * elem_photo1 = [TBXML childElementNamed:@"photo1" parentElement:elem_PLANT];
NSString *photo1Name = [TBXML textForElement:elem_photo1];
TBXMLElement * elem_photo2 = [TBXML childElementNamed:@"photo2" parentElement:elem_PLANT];
NSString *photo2Name = [TBXML textForElement:elem_photo2];
TBXMLElement * elem_photo3 = [TBXML childElementNamed:@"photo3" parentElement:elem_PLANT];
NSString *photo3Name = [TBXML textForElement:elem_photo3];
TBXMLElement * elem_photo4 = [TBXML childElementNamed:@"photo4" parentElement:elem_PLANT];
NSString *photo4Name = [TBXML textForElement:elem_photo4];
TBXMLElement * elem_photo5 = [TBXML childElementNamed:@"photo5" parentElement:elem_PLANT];
NSString *photo5Name = [TBXML textForElement:elem_photo5];
NSDictionary *dictionary = [[NSDictionary alloc]initWithObjects:@[titleName, thumbName, photo1Name, photo2Name, photo3Name, photo4Name, photo5Name] forKeys:@[@"title", @"thumb_url", @"photo1", @"photo2", @"photo3", @"photo4", @"photo5",]];
elem_PLANT = [TBXML nextSiblingNamed:@"principal" searchFromElement:elem_PLANT];
[_storeArray addObject:dictionary];
[self startLoading:dictionary];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [_carousel reloadData]; }];
}
}
}
};
// Create a failure block that gets called if something goes wrong
TBXMLFailureBlock failureBlock = ^(TBXML *tbxmlDocument, NSError * error) {
NSLog(@"Error! %@ %@", [error localizedDescription], [error userInfo]);
};
// Initialize TBXML with the URL of an XML doc. TBXML asynchronously loads and parses the file.
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:newURL]
success:successBlock
failure:failureBlock];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
FXImageView *imageView = [[FXImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.asynchronous = YES;
imageView.reflectionScale = 0.5f;
imageView.reflectionAlpha = 0.25f;
imageView.reflectionGap = 10.0f;
imageView.shadowOffset = CGSizeMake(0.0f, 2.0f);
imageView.shadowBlur = 5.0f;
imageView.cornerRadius = 10.0f;
view = imageView;
}
//show placeholder
((FXImageView *)view).processedImage = [UIImage imageNamed:@"placeholder.png"];
//set image
NSLog(@"%@", _storeArray);
if (_storeArray) {
NSDictionary *tempdic = [_storeArray objectAtIndex:0];
switch (index) {
case 0:
[(FXImageView *)view setImageWithContentsOfURL:[NSURL URLWithString:[tempdic objectForKey:@"photo1"]]];
break;
case 1:
[(FXImageView *)view setImageWithContentsOfURL:[NSURL URLWithString:[tempdic objectForKey:@"photo2"]]];
break;
case 2:
[(FXImageView *)view setImageWithContentsOfURL:[NSURL URLWithString:[tempdic objectForKey:@"photo3"]]];
break;
case 3:
[(FXImageView *)view setImageWithContentsOfURL:[NSURL URLWithString:[tempdic objectForKey:@"photo4"]]];
break;
case 4:
[(FXImageView *)view setImageWithContentsOfURL:[NSURL URLWithString:[tempdic objectForKey:@"photo5"]]];
break;
default:
break;
}
}
return view;
}
나는이 코드를 명확하게 보여 그냥 캔트 편집 ... – Marckaraujo
감사 @Kerni, 느릅 나무 버튼이 명확하게 코드를 보여줍니다 눌러합니까? – Marckaraujo
_storeArray가 nil이 아니기 때문에 객체가 포함 된 것은 아닙니다. _storeArray에 객체를 어디에 추가합니까? 빈 배열이므로 objectAtIndex : 0이 존재하지 않습니다. –