Сбой приложения при индикаторе Loading UIalertview при загрузке данных в iphone - PullRequest
0 голосов
/ 29 октября 2011

Я вызываю URL на моем событии кнопки поиска, чтобы загрузить данные.Я поставил код для загрузки индикатора Alert, взяв 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 toПоказывать индикатор загрузки при загрузке данных сзади.

  - (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 ]

1 голос
/ 30 октября 2011

Переменная alertMe автоматически выпущена, и поэтому вы не можете просто отправить ей сообщение о выпуске. Удалите строку [alertMe release];, и она будет отлично работать.

0 голосов
/ 30 октября 2011

Вы, вероятно, получаете доступ к освобожденному объекту. Чтобы увидеть, какой это, установите NSZombiesEnabled - это покажет вам, к какому уже выпущенному объекту вы пытаетесь получить доступ, и вы сможете определить свою проблему.

Пожалуйста, посмотрите здесь, чтобы увидеть, как включить зомби в XCode 4:

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

...