在加载iphone中的数据时,应用程序在加载UIalertview指示器时崩溃

时间:2011-10-29 17:09:16

标签: iphone nsthread

我在我的搜索按钮事件上调用URL来加载数据。我已经通过NSThread放置了加载指示器警报视图的代码。我使用3.2 xcode和4.3 iOS。每个东西都运行平稳但在搜索按钮上显示加载指示器,然后崩溃并在控制台中显示以下内容

Program received signal:  “EXC_BAD_ACCESS”.
warning: Unable to read symbols for  /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.2  (8H7)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).

搜索按钮点击事件下的代码:

 - (IBAction) searchButton {

if([addressField.text length]==0)
  {
    UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"Alert"  message:@"Please Tap on 'Show Me' & choose the 'Radius' first!!!" delegate:self  cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
    [myAlert show];

}
    else 

    {       

    [NSThread detachNewThreadSelector:@selector(updateFilterProgress) toTarget:self withObject:nil];

appDelegate = (MapTutorialAppDelegate *)[[UIApplication sharedApplication] delegate];

    CLLocationCoordinate2D location;
   float radius = [[arrayNo objectAtIndex:[pickerView selectedRowInComponent:0]] floatValue];

 NSString *url = [NSString stringWithFormat:@"http://....url...../hespdirectory/phpsqlsearch_genxml.php?lat=%f&lng=%f&radius=%f",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude,radius];

NSLog(@"%@", url);
 NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
    [xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];

    if(success)

{                    

if([appDelegate.markers count] == 0){

UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"Alert" message:@"No results fond!!!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
        [myAlert show];

}

else
{
resultButton.userInteractionEnabled = YES;

for (int i = 0; i < [appDelegate.markers count]; i++)
{

    marker *aMarker = [appDelegate.markers objectAtIndex:i];
    location.latitude = [aMarker.lat floatValue];
    location.longitude =[aMarker.lng floatValue];
    AddressAnnotation *annob = [[AddressAnnotation alloc]  initWithCoordinate:location];
    annob.title = aMarker.name;
    annob.subTitle = aMarker.address;
    [mapView addAnnotation:annob];
    [annob release];


    CLLocationCoordinate2D ausLoc = {location.latitude,location.longitude};             //for zoom in the showroom results region
    MKCoordinateSpan ausSpan = MKCoordinateSpanMake(0.108889, 0.169922);
    MKCoordinateRegion ausRegion = MKCoordinateRegionMake(ausLoc, ausSpan);
    NSLog(@"No Errors");
    mapView.region = ausRegion;


}

    }

}
else
    NSLog(@"Error Error Error!!!");

[addressField resignFirstResponder];

}

}

NSThread在后面加载数据时显示Loaading指标。

  - (void) updateFilterProgress{
NSAutoreleasePool *pool = [NSAutoreleasePool new];

Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];

if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
    UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"No Internet  Connection" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
    [myAlert show];

}
else{

    UIAlertView *alertMe = [[[UIAlertView alloc] initWithTitle:@"Loading..."  message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
    [alertMe show];

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    // Adjust the indicator so it is up a few pixels from the bottom of the  alert
    indicator.center = CGPointMake(alertMe.bounds.size.width / 2, alertMe.bounds.size.height - 50);
    [indicator startAnimating];
    [alertMe addSubview:indicator];
    [indicator release];
    [alertMe release];

    for (int i = 200; i > [appDelegate.markers count]; i--)
    {

        marker *aMarker = [appDelegate.markers objectAtIndex:i];

        [alertMe dismissWithClickedButtonIndex:0 animated:YES];
    }
  }
[pool release]; }

我的代码中是否还有其他内容。请求纠正我......

2 个答案:

答案 0 :(得分:1)

变量alertMe是自动释放的,因此您不能只发送一条释放消息。删除行[alertMe release];,它将完美运行。

答案 1 :(得分:0)

您可能正在访问已发布的对象。要查看它是哪一个,请设置 NSZombiesEnabled - 这将显示您尝试访问的已发布对象,并且您应该能够识别问题。

请看这里看看如何在XCode 4中启用僵尸:

http://42games.net/quick-note-on-setting-nszombieenabled-environment-variable-in-xcode-4/