내 응용 프로그램에서 동적 xml 피드로 채워진 테이블을 사용합니다. 그랜트 폴 (Grant Paul)이 작성한 코드를 새로 고침하여 새로운 콘텐츠가있는 테이블을 다시로드하는 방법도 있습니다. 셋째, 테이블을 다시로드 할 때 Apple의 Reachability를 사용하여 인터넷 연결을 확인합니다. 내 문제는 이것입니다. 인터넷 연결로 응용 프로그램을 열면 응용 프로그램이 실행되는 동안 인터넷 연결이 닫히고 응용 프로그램을 새로 고치면 충돌이 발생합니다. 앱이 Reachable과 NotReachable간에 전환 할 때 어떤 일이 일어나고 있습니다. 아래는 제 코드입니다. 애플 리케이션 스레드 6 실패 :이 줄에 신호 SIGABRT : TFHppleElement * 요소 = [요소 objectAtIndex : 0];iOS 테이블 뷰 새로 고침 문제
다음2012-10-02 14:00:03.715 FireCom[2229:1517] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x2d63012 0x21a0e7e 0x2d050b4 0x603f 0xd810d5 0xd81034 0x96213557 0x961fdcee)
libc++abi.dylib: terminate called throwing an exception
(lldb)
가 도달 가능성 코드입니다 : 내가 당신의 문제를 볼 생각
- (void)loadCallList
{
Reachability* reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
NetworkStatus netStatus = [reach currentReachabilityStatus];
switch (netStatus)
{
case NotReachable:
{
NSLog(@"Access Not Available");
[pull finishedLoading];
[self displayInternetMessage];
break;
}
case ReachableViaWWAN:
{
NSLog(@"Reachable WWAN");
// Parse HTML for random ID and create XML link
NSURL *theURL = [NSURL URLWithString:@"http://www.wccca.com/PITS/"];
NSData *data = [[NSData alloc] initWithContentsOfURL:theURL];
xpathParser = [[TFHpple alloc] initWithHTMLData:data];
NSArray *elements = [xpathParser searchWithXPathQuery:@"//input[@id='hidXMLID']//@value"];
TFHppleElement *element = [elements objectAtIndex:0];
TFHppleElement *child = [element.children objectAtIndex:0];
NSString *idValue = [child content];
NSString *idwithxml = [idValue stringByAppendingFormat:@".xml"];
NSString *url = @"http://www.wccca.com/PITS/xml/fire_data_";
NSString *finalurl = [url stringByAppendingString:idwithxml];
xmlParser = [[XMLParser alloc] loadXMLByURL:finalurl];
if (xmlParser.calls.count == 0)
{
self.headerHeight = 0.0;
UIAlertView *noCalls = [[UIAlertView alloc] initWithTitle:@"No Current Calls"
message:@"There are no current 9-1-1 calls in Clackamas or Washington County."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[noCalls show];
[noCalls release];
}
else
{
self.headerHeight = 45.0;
}
[callsTableView reloadData];
[pull finishedLoading];
break;
}
case ReachableViaWiFi:
{
NSLog(@"Reachable WiFi");
// Parse HTML for random ID and create XML link
NSURL *theURL = [NSURL URLWithString:@"http://www.wccca.com/PITS/"];
NSData *data = [[NSData alloc] initWithContentsOfURL:theURL];
xpathParser = [[TFHpple alloc] initWithHTMLData:data];
NSArray *elements = [xpathParser searchWithXPathQuery:@"//input[@id='hidXMLID']//@value"];
TFHppleElement *element = [elements objectAtIndex:0];
TFHppleElement *child = [element.children objectAtIndex:0];
NSString *idValue = [child content];
NSString *idwithxml = [idValue stringByAppendingFormat:@".xml"];
NSString *url = @"http://www.wccca.com/PITS/xml/fire_data_";
NSString *finalurl = [url stringByAppendingString:idwithxml];
xmlParser = [[XMLParser alloc] loadXMLByURL:finalurl];
if (xmlParser.calls.count == 0)
{
self.headerHeight = 0.0;
UIAlertView *noCalls = [[UIAlertView alloc] initWithTitle:@"No Current Calls"
message:@"There are no current 9-1-1 calls in Clackamas or Washington County."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[noCalls show];
[noCalls release];
}
else
{
self.headerHeight = 45.0;
}
[callsTableView reloadData];
[pull finishedLoading];
break;
}
}
}
당신의 코드는'elements' 배열에 데이터가 있다고 가정합니다. 먼저 nil 또는 count == 0인지 확인하고 '데이터 없음'시나리오를 처리하는 논리를 추가해야합니다. – Jeremy
요소 배열에는 항상 데이터가 있습니다. 그것은 결코 비어 있지 않을 것이다. –
'xpathParser'가 id가'hidXMLID' 인 요소를 찾을 수 없다면? 나는 그 해답이 데이터에 있다고 생각한다. 당신은 당신이 생각하는 것을 되돌려주지 않습니다. 당신의 문제는 꽤 잘랐다. 요소에는 아무 것도 없으므로 오류가 발생합니다. – Jeremy