Customized Annotation - iphone

i have a question regarding customized annotation here. Here is how i show the pin but i wish to insert an image in to the annotation when the user click on the pin. how can i do that?
- (void) showMarkingOnMap:(Service *) ser
{
if (!self.mapView.loaded) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"iPoly"
message:#"Failed to load the map."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
return;
}
id<AGSLayerView> graphicsLayerView = [self.mapView.mapLayerViews objectForKey:#"GraphicsLayer"];
AGSGraphicsLayer *graphicsLayer = (AGSGraphicsLayer*)graphicsLayerView.agsLayer;
[graphicsLayer removeAllGraphics];
// Create a symbols png graphic
AGSPictureMarkerSymbol *genSymbol = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:#"pushpin.png"];
ServiceInfoTemplate *infoTemplate = [[ServiceInfoTemplate alloc] init];
AGSGraphic *genGraphic;
AGSPoint *genPt;
NSMutableDictionary *dic= [[NSMutableDictionary alloc] init];
[dic setObject:[ser name] forKey:#"NAME"];
if([ser.location isEqualToString: #"\n"] || (ser.location == nil)){
[dic setObject:#"" forKey:#"DESC"];
} else {
[dic setObject:[ser location] forKey:#"DESC"];
}
genPt = [AGSPoint pointWithX:[[ser xcoordinate] floatValue]
y:[[ser ycoordinate] floatValue]
spatialReference:self.mapView.spatialReference];
genGraphic = [[AGSGraphic alloc] initWithGeometry:genPt symbol:genSymbol attributes:dic infoTemplateDelegate:infoTemplate];
[graphicsLayer addGraphic:genGraphic];
[graphicsLayer dataChanged];
[self.mapView zoomWithFactor:0.1 atAnchorPoint:genPt.cgPoint animated:NO];
[self.mapView centerAtPoint:genPt animated:YES];
//CGPoint *pt = CGPointMake([[ser ycoordinate] floatValue], [[ser xcoordinate] floatValue]);
}

It's not as easy as you might hope/think. Here's a full tutorial on how to do it.
Note that with this implementation, your callout will occupy the entire width of the view.
See:
http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/

Related

Three else-if statements [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Hi I am trying to have 4 buttons and each of them have different alerts when pressed. I am running into an issue, I had 3 buttons and I decided to add a "Rate My App" Button but now it isnt' working, please help me. (By the way the error is Expexted Exspression)(Org.=Organization (Fixed in App), Email- Real email in app,
#define TAG_Band 1
#define TAG_DEV 2
#define TAG_EDEV 3
#define TAG_RATE 4
#interface Org.ContactInfo () <MFMailComposeViewControllerDelegate>
#end
#implementation Org.ContactInfo:UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Contacts";
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)ContactBand:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Contact the Band" message:#"Contact the Org. or go to their website!" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Visit the Org. Website",#"E-Mail The Org. President", #"E-Mail The Org. Treasurer", nil];
alert.tag = TAG_Band;
[alert show];
}
-(IBAction)ContactDev:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Contact Me" message:#"Contact Me on Features you would like me to consider! I will do my Best to look at all of the Suggestions!" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Visit My Website",#"E-Mail Me!", nil];
alert.tag = TAG_DEV;
[alert show];
}
-(IBAction)RateMyApp:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Rate My App" message:#"When Your Reviewing my App, Please remember that this app was at no cost to the Mighty Mustang Band." delegate:self cancelButtonTitle:#"Not Right Now" otherButtonTitles:#"Rate My App!!", nil];
alert.tag = TAG_RATE;
[alert show];
}
-(IBAction)AppInfo:(id)sender;{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Version 1.0" message:#"More Updates Coming Soon. Please Feel Free to E-Mail me on features that you would like me to consider" delegate:self cancelButtonTitle:#"Not Right Now" otherButtonTitles:#"Email-Me", nil];
alert.tag = TAG_EDEV;
[alert show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == TAG_Band){
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://URL.org"]];
}
else if (buttonIndex==2){
//Subject
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"Org. President";
NSArray *toRecipients = [NSArray arrayWithObject:#"Person#Org.org"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
else if (buttonIndex==3){
//Subject
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"Org. Treasurer, ";
NSArray *toRecipients = [NSArray arrayWithObject:#"Person#Org.org"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_DEV){
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://stepheniosdeveloper.wordpress.com"]];
}
else if (buttonIndex==2){
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"";
NSArray *toRecipients = [NSArray arrayWithObject:#"Email#gmail.com"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_EDEV);{
if (buttonIndex==1){
NSString *emailTitle = #"";
//Recipients
NSString *emailBody=#"";
NSArray *toRecipients = [NSArray arrayWithObject:#"Email#gmail.com"];
MFMailComposeViewController *mc=[[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setSubject:emailBody];
[mc setToRecipients:toRecipients];
[self presentViewController:mc animated:YES completion:NULL];
}
}
else if (alertView.tag == TAG_RATE);{ //Expected Expression
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/us/app/Org/id607257427?ls=1&mt=8"]];
}
}
}
It worked Before I added the last on (TAG_RATE) but now I don't understand why it isn't working anymore. Please Help.
There is a typo in your code: you have extra ; after the last two else if conditions:
else if (alertView.tag == TAG_EDEV)/*;*/{ // extra `;`
//...
}
else if (alertView.tag == TAG_RATE)/*;*/{ // extra `;` //Expected Expression
// ...
}

UIActivityViewController Background Color

So I have a UIActivityViewController in my Application. How do I change the background color.
And I also have a quick how to add Facebook and twitter to my UIActivityViewController.
The Code:
- (IBAction)Social:(id)sender {
UIActivityViewController *social = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:#"Travel+ Rocks",nil] applicationActivities:nil];
social.excludedActivityTypes = #[UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypePostToWeibo,UIActivityTypePrint];
[self presentViewController:social animated:YES completion:nil];
[social setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(#"Activity = %#",activityType);
NSLog(#"Completed Status = %d",completed);
if (completed)
{
// UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Your Posts were sucessful" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
// [objalert show];
// objalert = nil;
}else
{
// UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Your Posts weren't sucessful" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
// [objalert show];
// objalert = nil;
}
}];
}
These Piece of Code fix the Background Eror:
NSString *message = [NSString stringWithFormat:#""];
NSString *textToShare = message;
UIImage *imageToShare = [UIImage imageNamed:#""];
NSArray *activityItems = [[NSArray alloc] initWithObjects:textToShare, imageToShare,nil];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
[self presentViewController:activityVC animated:YES completion:nil];
Have a look on the following linked sample code you may get some idea...
https://github.com/coryalder/DMActivityInstagram/downloads
if you set the targets -> summary -> status Bar style the color of the share view will follow. that the best iv found out .....
hope it helps

iPhone Map application ipa crashing on iOS6

My Map application is on iTune market which runs good on iOS 4 and iOS 5. I have developed this application using Xcode 3.2, iPhone sdk 4.2 on Mac mini having Mac OS 10.6.8.
This application .ipa file is crashing after launching on iOS 6. I am developing app on MacMini and I could not able to run xcode 4.5 to rectify the crash. I am pasting some code which runs on launching. If there is some deprecated methods which causes crash then please help because I am not able to check this code without Mac OS 10.7(Lion)..
- (void)viewDidLoad {
if([appDelegate.markers count] == 0 && [mapView.annotations count] == 0 && UserId.data == 0)
{
[self performSelector:#selector(launchActivity) withObject:nil afterDelay:1.0];
}
}
- (void) launchActivity {
Reachability *r = [Reachability reachabilityWithHostName:#"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"No Internet Connectivity!" message:#"This app require an internet connection via WiFi or cellular network to work." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
else
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
if([self.mapView.annotations count] == 1)
{
}
if (locationManager.location == nil)
{
}
else
{
// Change map region using span (degrees)...
MKCoordinateSpan span = MKCoordinateSpanMake(0.001, 0.001);
MKCoordinateRegion region = MKCoordinateRegionMake
(locationManager.location.coordinate, span);
[mapView setRegion:region animated:YES];
}
mapView.showsUserLocation = YES;
BOOL locationAllowed = [CLLocationManager locationServicesEnabled];
if (locationAllowed==NO)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Location Service Disabled"
message:#"To re-enable, please go to Settings and turn on Location Service for this app."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
else
{
[NSThread detachNewThreadSelector:#selector(updateFilterProgress) toTarget:self withObject:nil]; //NSthread not taken because Default.png stay while loading the results
//========================================================================================== ==================================
//Searching Showroom Locations withing the radius
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
appDelegate = (HettichLocatorAppDelegate *)[[UIApplication sharedApplication] delegate];
CLLocationCoordinate2D location;
NSString *url = [[NSString alloc] initWithFormat:#"http://www.company.com.au/directory/phpsqlsearch_genxml.php?lat=%f&lng=%f&radius=5",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude];
radiusinurl.text = #"5km";
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];
[parser release];
[xmlParser release];
//[URL release];
[url release];
if(success)
{
annobjs = [[NSMutableArray array] retain];
if([appDelegate.markers count] == 0)
{
//some logic
}
else
{
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 *annobj = [[AddressAnnotation alloc] initWithCoordinate:location];
annobj.title = aMarker.name;
annobj.subtitle = aMarker.address;
[annobjs addObject:annobj];
[mapView addAnnotation:annobj];
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);
mapView.region = ausRegion;
[annobj release];
[_tableView reloadData];
}
}
}
else
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"" message:#"Unable to find the results." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
[pool release];
}
}
}
}

Application crashing at Loading UIalertview indicator while loading data in iphone

I am calling URL on my Search button event to load data. I have put the code for Loading indicator Alert view by taking NSThread. I am using 3.2 xcode with 4.3 iOS. Every thing run smooth but on search button it shows Loading indicator and then crashing and showing following in console
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).
Code under the Search Button click event:
- (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];
}
}
And for NSThread to Show Loaading indicator while loading data at the back.
- (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]; }
Is there anything remaining in my code. Pleas correct me....
The variable alertMe is autoreleased and therefore you can't just send a release message to it. Remove the line [alertMe release]; and it will run perfectly.
You are probably accessing a released object. To see which one it is, set NSZombiesEnabled - this will show you which already released object you try to access, and you should be able to identify your problem.
Please have a look here to see how to enable the zombies in XCode 4:
http://42games.net/quick-note-on-setting-nszombieenabled-environment-variable-in-xcode-4/

progressbar in UIAlertview issue while parsing

I want to resign UIAlertView containing activity indicator. I am putting following code. It is working while loading data but the UIalertview is not resigning after successful parsing. What condition should I give here???
- (void) updateFilterProgress{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Loading..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert 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(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[pool release];
}
ON my button click event I put following code
// **EDIT==1**
[NSThread detachNewThreadSelector:#selector(updateFilterProgress) toTarget:self withObject:nil];toTarget:self withObject:nil]; //for calling updateFilterProgress
NSString *url = [NSString stringWithFormat:#"http://....url...../hespdirectory/phpsqlsearch_genxml.php?lat=%f&radius=%f&lng=%f",lati,longi,radius];
//NSLog(#"NSString *url");
NSLog(#"%#", url);
//NSString *escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
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)
{ **//EDIT==2**
[alert dismissWithClickedButtonIndex:0 animated:YES]; //for resigning alertview
for (int i = 0; i < [appDelegate.markers count]; i++)
{
//marker *aMarker = [[marker alloc] init];
marker *aMarker = [appDelegate.markers objectAtIndex:i];
location.latitude = [aMarker.lat floatValue];
location.longitude =[aMarker.lng floatValue];
AddressAnnotation *annobj = [[AddressAnnotation alloc] initWithCoordinate:location];
annobj.title = aMarker.name;
[mapView addAnnotation:annobj];
[annobj release];
}
}
I want to resign this UIAlertView containing activity indicator.......
Set your UIAlertView and ActivityIndicator (and all objects inside the alert view) as members of your class file.
Then, where you'd normally release these items (and where you want to dismiss the alert) you can call this:
[myAlertView dismissWithClickedButtonIndex:0 animated:YES];
This has the same effect as if though the user clicked the cancel button on it, which is perfectly acceptable.
Hope this helps!