Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnection delegate methods not executing
    primarykey
    data
    text
    <p>I'm trying to pull images from the server for the scrollview. After the user zooms the view in or out, the image should be downloaded:</p> <pre><code>- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { Ymin=365000+375000*_scrollView.contentOffset.x/(scale*1024); Ymax=365000+375000*(_scrollView.contentOffset.x/scale+1024/scale)/1024; Xmin=6635000-260000*(_scrollView.contentOffset.y/scale+748/scale)/748; Xmax=6635000-260000*_scrollView.contentOffset.y/(scale*748); [self looYhendus]; //Creates NSURLConnection and downloads the image according to scale, Ymin, Ymax, Xmin and Xmax values UIImage *saadudPilt=_kaardiPilt; imageView=[[UIImageView alloc] initWithImage:saadudPilt]; imageView.frame=CGRectMake(_scrollView.contentOffset.x,_scrollView.contentOffset.y,1024,748); [_scrollView addSubview:imageView]; } </code></pre> <p>On some occasions (I can't figure out, on what conditions), it works, but on some occasions NSURLConnection delegate methods won't get fired and the image set as the subview is still the image that is initially downloaded (when the application launches). Then, only after I touch the screen again (the scrollview scrolls), the NSLog message shows that the image is downloaded. What could be the reason of this kind of a behaviour?</p> <p>EDIT: Added the NSURLConnection delegate methods. I've tried a few other ways but they all end up not executing the delegate methods. Which made me think that it's not about NSURConnection but rather UIScrollView (obviously, I can be wrong about this).</p> <pre><code>- (void)looYhendus { yhendused=CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks); NSString *aadress = [NSString stringWithFormat:@"http://xgis.maaamet.ee/wms-pub/alus?version=1.1.1&amp;service=WMS&amp;request=GetMap&amp;layers=MA-ALUSKAART&amp;styles=default&amp;srs=EPSG:3301&amp;BBOX=%d,%d,%d,%d&amp;width=%d&amp;height=%d&amp;format=image/png",Ymin,Xmin,Ymax,Xmax,512,374]; NSURL *url = [[NSURL alloc] initWithString:aadress]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if( theConnection ) { andmedServerist = [NSMutableData data]; CFDictionaryAddValue( yhendused, (__bridge void *)theConnection, (__bridge_retained CFMutableDictionaryRef)[NSMutableDictionary dictionaryWithObject:[NSMutableData data] forKey:@"receivedData"]); } CFRunLoopRun(); } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [andmedServerist setLength: 0]; } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSMutableDictionary *connectionInfo = (NSMutableDictionary*)objc_unretainedObject(CFDictionaryGetValue(yhendused, (__bridge void *)connection)); [[connectionInfo objectForKey:@"receivedData"] appendData:data]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Ühenduse viga" message:@"Kõige tõenäolisemalt on kaardiserveril probleeme või puudub seadmel internetiühendus" delegate:self cancelButtonTitle:@"Sulge" otherButtonTitles:nil]; [alert show]; CFRunLoopStop(CFRunLoopGetCurrent()); } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSMutableDictionary *connectionInfo = (NSMutableDictionary*)objc_unretainedObject(CFDictionaryGetValue(yhendused, (__bridge void *)connection)); [connectionInfo objectForKey:@"receivedData"]; andmedServerist=[connectionInfo objectForKey:@"receivedData"]; _kaardiPilt = [UIImage imageWithData: andmedServerist]; CFDictionaryRemoveValue(yhendused, (__bridge void *)connection); CFRunLoopStop(CFRunLoopGetCurrent()); } </code></pre> <p>EDIT: added this:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; Ymin=365000; Ymax=740000; Xmin=6375000; Xmax=6635000; [self looYhendus]; UIImage *saadudPilt=_kaardiPilt; imageView=[[UIImageView alloc] initWithImage:saadudPilt]; imageView.frame=CGRectMake(0,0,1024,748); [_scrollView addSubview:imageView]; [_scrollView setContentSize: CGSizeMake(1024, 748)]; _scrollView.minimumZoomScale = 1.0; _scrollView.maximumZoomScale = 50.0; _scrollView.delegate = self; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload