Turns out this is an iOS 5.1 Bug. It's well documented if the search is worded correctly :-)
I am using UIScrollView with paging subviews. Somehow these are generating leaks when I test my App in Instruments. I have reduced the code to this simple state and I still leak when thumbing between the 2 subviews. Paging is enabled on the scroll view. I am using ARC.
CGRect frame;
frame.origin.x = self.theScrollPart.frame.size.width * 0;
frame.origin.y = 0;
frame.size = self.theScrollPart.frame.size;
self->subview = [[UIView alloc] initWithFrame:frame];
[self.theScrollPart addSubview:subview];
frame.origin.x = self.theScrollPart.frame.size.width * 1;
frame.origin.y = 0;
frame.size = self.theScrollPart.frame.size;
self->subview2 = [[UIView alloc] initWithFrame:frame];
[self.theScrollPart addSubview:subview2];
self.theScrollPart.contentSize = CGSizeMake(self.theScrollPart.frame.size.width * 2, self.theScrollPart.frame.size.height);
The .h file is:
#property (weak, nonatomic) IBOutlet UIScrollView *theScrollPart;
#property (strong, nonatomic) IBOutlet UIView *subview;
#property (strong, nonatomic) IBOutlet UIView *subview2;
Thanks for any help and as always, sorry if I overlooked something obvious.
Related
I've facing one problem while developing my application.In my application there are more then 10 screens and have done with design too.But now i want to change whole color of the screen while user can open color picker and selected color will apply on all the screes.
Can any one suggest me that how can i do this one.because i have used lot's of imageview and images too.
Below is the example code where i have used the images in uitableview cell :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"CategoriesListCell";
CategoriesListCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[CategoriesListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
[cell.contentView setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
int row = indexPath.row * 2;
NSLog(#"row:::%d",row);
UIButton *btnCategoriesLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, btnWidth, rowHeight)];
UIImage *imgButton = [UIImage imageNamed:#"bgbutton"];
[btnCategoriesLeft setImage:imgButton forState:UIControlStateNormal];
[btnCategoriesLeft addTarget:self action:#selector(btnCatTapped:) forControlEvents:UIControlEventTouchUpInside];
[btnCategoriesLeft setTag:row];
//Set Transpernt images
UIImageView *imgViewLeft = [[UIImageView alloc] initWithFrame:CGRectMake(30, 30, 88, 53)];
[imgViewLeft setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.png",row]]];
[imgViewLeft setBackgroundColor:[UIColor clearColor]];
[btnCategoriesLeft addSubview:imgViewLeft];
//Set Title of label
UILabel *lblCategoriesTitleLeft = [[UILabel alloc]initWithFrame:CGRectMake(10, 80, 140, 20)];
lblCategoriesTitleLeft.backgroundColor = [UIColor clearColor];
lblCategoriesTitleLeft.textColor = [UIColor whiteColor];
[lblCategoriesTitleLeft setFont:FONT_WITH_SIZE_REGULAR(15.0)];
[lblCategoriesTitleLeft setText:[arrListOfCategories objectAtIndex:row]];
[lblCategoriesTitleLeft setTextAlignment:NSTextAlignmentCenter];
[btnCategoriesLeft addSubview:lblCategoriesTitleLeft];
[[cell contentView] addSubview:btnCategoriesLeft];
UIButton *btnCategoriesRight = [[UIButton alloc] initWithFrame:CGRectMake(btnWidth, 0, btnWidth, rowHeight)];
imgButton = [imgButton stretchableImageWithLeftCapWidth:imgButton.size.width/2 topCapHeight:imgButton.size.height/2];
[btnCategoriesRight setImage:imgButton forState:UIControlStateNormal];
[btnCategoriesRight setTag:row +1];
[btnCategoriesRight addTarget:self action:#selector(btnCatTapped:) forControlEvents:UIControlEventTouchUpInside];
//Set Transpernt images
UIImageView *imgViewRight = [[UIImageView alloc] initWithFrame:CGRectMake(40, 30, 88, 53)];
[imgViewRight setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.png",row+1]]];
[imgViewRight setBackgroundColor:[UIColor clearColor]];
[btnCategoriesRight addSubview:imgViewRight];
//Set Title of label
UILabel *lblCategoriesTitleRight = [[UILabel alloc]initWithFrame:CGRectMake(20, 80, 140, 20)];
lblCategoriesTitleRight.backgroundColor = [UIColor clearColor];
lblCategoriesTitleRight.textColor = [UIColor whiteColor];
[lblCategoriesTitleRight setFont:FONT_WITH_SIZE_REGULAR(15.0)];
[lblCategoriesTitleRight setText:[arrListOfCategories objectAtIndex:row+1]];
[lblCategoriesTitleRight setTextAlignment:NSTextAlignmentCenter];
[btnCategoriesRight addSubview:lblCategoriesTitleRight];
[[cell contentView] addSubview:btnCategoriesRight];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
Thanks.
I am a bit confused about how your sample code correlates to the question you're asking. If I understand this correctly, you would like to change the background color of all 10 or more screens with a slider. Try setting up red, blue, and green sliders and assigning global variables via the app delegate.
Add three sliders to interface builder.
Then set up three UISlider outlets.
YourSliderViewController.h
#interface YourViewController ()
#property (nonatomic, weak) IBOutlet UISlider *redSlider;
#property (nonatomic, weak) IBOutlet UISlider *blueSlider;
#property (nonatomic, weak) IBOutlet UISlider *greenSlider;
#end
YourSliderViewController.m
- (IBAction)changeColor:(id)sender{
float red = self.redSlider.value;
float green = self.greenSlider.value;
float blue = self.blueSlider.value;
UIColor *newColor = [UIColor colorWithRed:red
green:green
blue:blue
alpha:1.0];
self.view.backgroundColor = newColor;
}
The following is to make your RGB sliders accessible to all classes. That way you can set self.view.background = newColor in any other ViewController inside -viewDidLoad.
Create a pointer to the AppDelegate. I called mine appDel.
MyXcodeProject-Prefix.pch
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "AppDelegate.h"
AppDelegate *appDel;
#endif
AppDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UIColor *newColor;
#end
AppDelegate.m
appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
I have a problem with my MKPolyline.
I have added this code but I see no line. I get the coordinates form a webserver with a http-request. I save the coordinates as a double and show with that my annotations.
in the viewcontroller.h
#property (nonatomic, retain) MKPolyline *routeLine;
#property (nonatomic, retain) MKPolylineView *routeLineView;
in the viewcontroller.m
CLLocationCoordinate2D coordinateArray[7];
coordinateArray[0] = CLLocationCoordinate2DMake(theCoordinate0.latitude, theCoordinate0.longitude);
coordinateArray[1] = CLLocationCoordinate2DMake(theCoordinate1.latitude, theCoordinate1.longitude);
coordinateArray[2] = CLLocationCoordinate2DMake(theCoordinate2.latitude, theCoordinate2.longitude);
coordinateArray[3] = CLLocationCoordinate2DMake(theCoordinate3.latitude, theCoordinate3.longitude);
coordinateArray[4] = CLLocationCoordinate2DMake(theCoordinate4.latitude, theCoordinate4.longitude);
coordinateArray[5] = CLLocationCoordinate2DMake(theCoordinate5.latitude, theCoordinate5.longitude);
coordinateArray[6] = CLLocationCoordinate2DMake(theCoordinate6.latitude, theCoordinate6.longitude);
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:7];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[self.mapView addOverlay:self.routeLine];
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if(overlay == self.routeLine)
{
if(nil == self.routeLineView)
{
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine]autorelease];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 10;
}
return self.routeLineView;
}
return nil;
}
Have you verified that your mapview is connected to the mapview on screen (the IBOutlet in Interface Builder)? the next thing to check is that you've set the delegate. Check this by putting a breakpoint or a debug statement in the viewForOverlay function.
P.S. with that code you're only ever going to be able to draw one line. It relies on self.routeLine and self.routeLineView and you only have one of each of those.
This is my question....
I have a mapView and i fill the view with several custom pins.
I would different custom pins in my mapView.
I have tried with an IF condition but don't work.
I don't understand how the called to method works.
Follow the code.
Vi allego il codice.
//Customization of my pins
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation(id<MKAnnotation>)annotation{
static NSString *identifier = #"";
MKAnnotationView *pin = [ mappa dequeueReusableAnnotationViewWithIdentifier:identifier ];
//OLD COORDINATES
if(newcoordinate == FALSE){
pin = [[[ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:identifier ]autorelease];
pin.image = [ UIImage imageNamed:#"old.png" ]
}
// NEW COORDINATES
else ( newcoordinate == TRUE){
pin = [[[ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:identifier ]autorelease];
pin.image = [ UIImage imageNamed:#"new.png" ];
}
pin.canShowCallout = YES;
//CALLOUT INFO
UIImage *image = [UIImage imageNamed:#"informations.png"];
UIImageView *imgView = [[[UIImageView alloc] initWithImage:image]autorelease];
pin.leftCalloutAccessoryView = imgView;
pin.annotation = annotation;
return pin;}
The result is... several pin in the same mapView but with the same customization.
:/
Thank you.
SOLVED.
I have added a new property in MyAnnotation class:
#interface MyAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
BOOL isNew; // <------- My solution
}
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *subtitle;
#property (nonatomic, assign) BOOL isNew ; <--------- My solution
Today i have learned what are the properties.
Is there a callback offered by UIWebView that is called when scrolling occurs, and if so, how can I get the current content offset?
Thanks.
You can using this property available in ios 5.0:
#property(nonatomic, readonly, retain) UIScrollView *scrollView
Or prior to iOS 5.0:
NSArray *subViews = [NSArray arrayWithArray:[myWebview subviews]];
UIScrollView *webScroller = (UIScrollView *)[subViews objectAtIndex:0];
You can then implement the UIScrollViewProtocol and do something like this:
UIScrollView *webScrollView = myWebView.scrollView;
webScrollView.delegate = self;
//implement method from delegate..
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//Scrolled
}
To get the contentOffset all you have to do is:
CGPoint offSet = webScrollView.contentOffset;
I've spent many hours trying to figure how to do this:
Having a placemark/annotation in the centerCoordinate of your mapView, when you scroll the map, the placemark should always stays in the center.
I've seen another app doing this too!
Found my question in How to add annotation on center of map view in iPhone?
There's the answer :
If you want to use an actual annotation instead of just a regular view positioned above the center of the map view, you can:
use an annotation class with a settable coordinate property (pre-defined MKPointAnnotation class eg). This avoids having to remove and add the annotation when the center changes.
create the annotation in viewDidLoad
keep a reference to it in a property, say centerAnnotation
update its coordinate (and title, etc) in the map view's regionDidChangeAnimated delegate method (make sure map view's delegate property is set)
Example:
#interface SomeViewController : UIViewController <MKMapViewDelegate> {
MKPointAnnotation *centerAnnotation;
}
#property (nonatomic, retain) MKPointAnnotation *centerAnnotation;
#end
#implementation SomeViewController
#synthesize centerAnnotation;
- (void)viewDidLoad {
[super viewDidLoad];
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = mapView.centerCoordinate;
pa.title = #"Map Center";
pa.subtitle = [NSString stringWithFormat:#"%f, %f", pa.coordinate.latitude, pa.coordinate.longitude];
[mapView addAnnotation:pa];
self.centerAnnotation = pa;
[pa release];
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
centerAnnotation.coordinate = mapView.centerCoordinate;
centerAnnotation.subtitle = [NSString stringWithFormat:#"%f, %f", centerAnnotation.coordinate.latitude, centerAnnotation.coordinate.longitude];
}
- (void)dealloc {
[centerAnnotation release];
[super dealloc];
}
#end
Now this will move the annotation but not smoothly. If you need the annotation to move more smoothly, you can add a UIPanGestureRecognizer and UIPinchGestureRecognizer to the map view and also update the annotation in the gesture handler:
// (Also add UIGestureRecognizerDelegate to the interface.)
// In viewDidLoad:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
panGesture.delegate = self;
[mapView addGestureRecognizer:panGesture];
[panGesture release];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
pinchGesture.delegate = self;
[mapView addGestureRecognizer:pinchGesture];
[pinchGesture release];
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
centerAnnotation.coordinate = mapView.centerCoordinate;
centerAnnotation.subtitle = [NSString stringWithFormat:#"%f, %f", centerAnnotation.coordinate.latitude, centerAnnotation.coordinate.longitude];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
//let the map view's and our gesture recognizers work at the same time...
return YES;
}