Annotation not dragging - dictionary

MapPin.h :
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface MapPin : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
#property (nonatomic,readwrite,assign)CLLocationCoordinate2D coordinate;
- (id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:(NSString *)placeName description:(NSString *)description;
-(void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;
#end
and here's the MapPin.m
#import "MapPin.h"
#implementation MapPin
#synthesize coordinate;
-(NSString *)subtitle{
return nil;
}
-(NSString *)title{
return nil;
}
-(id)initWithCoordinates:(CLLocationCoordinate2D)location placeName:(NSString *)placeName description:(NSString *)description{
coordinate=location;
return self;
}
-(CLLocationCoordinate2D)location{
return coordinate;
}
-(void)setCoordinate:(CLLocationCoordinate2D)newCoordinate{
coordinate=newCoordinate;
}
#end
In the ViewController.h i've adopted the MKMapViewDelegate protocol.
and here's the ViewController.m :
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pin = (MKPinAnnotationView *)[self.MyMap dequeueReusableAnnotationViewWithIdentifier:#"myPin"];
if(pin == nil){
pin=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:#"myPin"];
}
else{
pin.annotation=annotation;
}
pin.draggable=YES;
return pin;
}
//Add Location button
- (IBAction)AddPin:(id)sender {
CLLocationCoordinate2D center;
center.latitude=Locate.location.coordinate.latitude;
center.longitude=Locate.location.coordinate.longitude;
MKCoordinateRegion region;
region.center=center;
region.span.latitudeDelta=0.2f;
region.span.longitudeDelta=0.2f;
MapPin *myPin = [[MapPin alloc]initWithCoordinates:self.MyMap.centerCoordinate placeName:#"LoMinder!" description:#"Set Location for LoMinder!"];
[_MyMap addAnnotation:myPin];
}
//Dropping the pin:
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState
{
//Region
MKCoordinateRegion myRegion;
//Center
CLLocationCoordinate2D center;
if (newState == MKAnnotationViewDragStateStarting)
{
[_MyMap setRegion:myRegion animated:YES];
}
if(newState == MKAnnotationViewDragStateDragging)
{
myRegion.center=annotationView.annotation.coordinate;
myRegion.span.latitudeDelta=0.2f;
myRegion.span.longitudeDelta=0.2f;
[_MyMap setRegion:myRegion animated:YES];
}
if(newState==MKAnnotationViewDragStateEnding)
{
arrived=self.MyMap.centerCoordinate;
center=annotationView.annotation.coordinate;
myRegion.center=center;
myRegion.span.latitudeDelta=0.2f;
myRegion.span.longitudeDelta=0.2f;
[_MyMap setRegion:myRegion animated:YES];
}
}
/////
I've also imported the MapPin.h into the ViewController.
When I run my app, I should press the Add Location button in ord er to get the annotation pin, I press the button, the annotation pin appears on the map, but the problem is that when i try to drag it, it seems to be un-draggable.
Please people some help.
Thank you :)

Solved by changing the title method in the MapPin.m
Make it return anything but nil.

Related

trouble sending data to detailview

I am using collection view to get data from my server display some of it in a cell and then I have a segue to the destination view controller I got the image to update correctly but for some reason the text is not going to my UITextView
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
//DetailSegue
if ([segue.identifier isEqualToString:#"DetailSegue"]) {
ICBCollectionViewCell *cell = (ICBCollectionViewCell *)sender;
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
ICBDetailViewController *dvc = (ICBDetailViewController *)[segue destinationViewController];
path = [paths objectAtIndex:indexPath.row];
Path = [path objectForKey:#"path"];
title = [titles objectAtIndex:indexPath.row];
Title = [title objectForKey:#"title"];
sku = [SKUs objectAtIndex:indexPath.row];
Sku = [sku objectForKey:#"SKU"];
longDescrip = [longDescription objectAtIndex:indexPath.row];
LongDescrip = [longDescrip objectForKey:#"longDescrip"];
LongDescrip =#"Hello World";
NSLog(#"Descrip =%#",LongDescrip);
NSString *iconTitle =[NSString stringWithFormat:#"%#.png",Sku];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fullPath = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:#"/%#",iconTitle]]; //add our image to the path
dvc.img = [[UIImage alloc] initWithContentsOfFile:fullPath];
dvc.title = Title;
//UITextView *descrip = (UITextView *)[cell viewWithTag:120];
[dvc.descrip setText:#"Hello"];
}
}
I am not sure if it has something to do with the fact that the object being sent to is a UITextView and I am sending it a String
or if I have something hooked up wrong
here is the .m and .h for the detailController also
the .h
#import <UIKit/UIKit.h>
#interface ICBDetailViewController : UIViewController
#property(weak) IBOutlet UIImageView *imageView;
#property (strong) UIImage *img;
#property(weak) IBOutlet UITextView *descrip;
#end
the .m
#import "ICBDetailViewController.h"
#interface ICBDetailViewController ()
#end
#implementation ICBDetailViewController
#synthesize imageView, img, descrip;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.image = self.img;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Hopefully somebody will see what I have missed for two days
after again reviewing it all I noticed i missed the outlet in the .h and forgot to set it show in the ViewDidLoad of the .m I also missed hooking upthe referencing outlet to my txtView

cocos3d billboard paning with gestures

I want to pan the billboard using using gestures how can i do that, i have modified the DemoMashUp like this:
- (void)dragBy: (CGPoint) aMovement atVelocity: (CGPoint) aVelocity
{
if (selectedNode == dieCube || selectedNode == texCubeSpinner) {
[self rotate: ((SpinningNode*)selectedNode) fromSwipeVelocity: aVelocity];
}
if (selectedNode==marker) {
[self moveSelectedNode:marker fromSwipeMovement:aMovement];
}
}
- (void)stopDragging
{
selectedNode = nil;
}
- (void)moveSelectedNode:(CC3Billboard*) aNode fromSwipeMovement: (CGPoint) swipeMovement
{
aNode.location=cc3v(swipeMovement.x, swipeMovement.y, aNode.location.z);
}
but its not working and when i touch the billboard it disapears
i made a new method moveSelectedNode "DemoMashUpScene" like this :
-(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {
NSLog(#"\n\n*******************TOUCH EVEN CALLED************************\n\n");
switch (touchType) {
case kCCTouchBegan:
[self pickNodeFromTouchEvent: touchType at: touchPoint];
break;
case kCCTouchMoved:
if (selectedNode==marker||selectedNode==marker1||selectedNode==marker2||selectedNode==marker3||selectedNode==marker4||selectedNode==marker5)
{
[self moveSelectedNode:marker1 fromSwipeMovement:touchPoint];
}
break;
case kCCTouchEnded:
selectedNode = nil;
break;
default:
break;
}
lastTouchEventPoint = touchPoint;
lastTouchEventTime = now;
}
-(void) moveSelectedNode: (CC3Billboard*) aNode fromSwipeMovement: (CGPoint) swipeMovement {
CC3Vector vector= CC3VectorMake(swipeMovement.x * 3, swipeMovement.y * 3, 0);
aNode.location=cc3v(aNode.location.x, aNode.location.y, 0.0);
aNode.location=CC3VectorAdd(aNode.location,vector);
CCLOG(#"%#",aNode.name);
// NSLog(#"\n\n ******MOVING****%f_____%f*****____%f",vector.x,vector.y,vector.z);
}

Simulator does not show button text

I'm learning to build iPhone apps with XCode 4.5.2 and I noticed something strange. As you can see at the address http://i.stack.imgur.com/purI8.jpg the text inside one of the buttons is not displayed in the iOS6 simulator. I also tried to move the Enter button in the same line of 0 and -, but the text in all three buttons of the line disappeared. Anyone knows what's the cause of this problem and how to solve it? Here is the code:
#import "CalculatorViewController.h"
#import "CalculatorBrain.h"
#interface CalculatorViewController()
#property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
#property (nonatomic, strong) CalculatorBrain *brain;
#end
#implementation CalculatorViewController
#synthesize display;
#synthesize userIsInTheMiddleOfEnteringANumber;
#synthesize brain = _brain;
- (CalculatorBrain *)brain
{
if (!_brain) _brain = [[CalculatorBrain alloc] init];
return _brain;
}
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = [sender currentTitle];
if (self.userIsInTheMiddleOfEnteringANumber) {
self.display.text = [self.display.text stringByAppendingString:digit];
} else {
self.display.text = digit;
self.userIsInTheMiddleOfEnteringANumber = YES;
}
}
- (IBAction)enterPressed
{
[self.brain pushOperand:[self.display.text doubleValue]];
self.userIsInTheMiddleOfEnteringANumber = NO;
}
- (IBAction)operationPressed:(UIButton *)sender
{
if (self.userIsInTheMiddleOfEnteringANumber) [self enterPressed];
NSString *operation = [sender currentTitle];
double result = [self.brain performOperation:operation];
self.display.text = [NSString stringWithFormat:#"%g", result];
}
#end
According to https://developer.apple.com/library/ios/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/doc/uid/TP40006815-CH3-SW7
- (void)setTitle:(NSString *)title forState:(UIControlState)state
To set your button titles.
So in your case:
- (IBAction)operationPressed:(UIButton *)sender{
....
[sender setTitle:[NSString stringWithFormat:#"%g", result] forState: UIControlStateNormal];
// lets assume you want the down states as well:
[sender setTitle:[NSString stringWithFormat:#"%g", result] forState: UIControlStateSelected];
[sender setTitle:[NSString stringWithFormat:#"%g", result] forState: UIControlStateHighlighted];
}

Thread 1:EXC_BAD_ACCESS(code=2, address=0xbf7ffffc)

Am writing a simple multi view application with one root controller and two view controllers (blue and yellow). When I try to run it in the iPhone Simulator, I get an error by the #synthesize property. I have commented out the error on that line.
Can you tell me what the error means, and how can I get the app to run?
Thank you.
#import "SwitchViewController.h"
#import "BlueViewController.h"
#import "YellowViewController.h"
#interface SwitchViewController ()
#end
#implementation SwitchViewController
#synthesize yellowViewController;
#synthesize blueViewController; //Thread 1:EXC_BAD_ACCESS(code=2, address=0xbf7ffffc)
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
// If you create your views manually, you MUST override this method and use it to create your views.
// If you use Interface Builder to create your views, then you must NOT override this method.
}
- (void)viewDidLoad
{
self.blueViewController = [[BlueViewController alloc]initWithNibName:#"BlueView" bundle:nil];
[self.view insertSubview:self.blueViewController.view atIndex:0];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)switchViews:(id)sender
{
if(self.yellowViewController.view.superview==nil) {
if(self.yellowViewController==nil) {
self.yellowViewController =
[[YellowViewController alloc] initWithNibName:#"YellowView" bundle:nil];
}
[blueViewController.view removeFromSuperview];
[self.view insertSubview:self.yellowViewController.view atIndex:0];
} else {
if (self.blueViewController == nil) {
self.blueViewController =
[[BlueViewController alloc] initWithNibName:#"BlueView" bundle:nil];
}
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use
if (self.blueViewController.view.superview == nil) {
self.blueViewController = nil;
} else {
self.yellowViewController = nil;
}
}
#end
Comment out the loadView method in your SwitchViewController, BlueViewController, and YellowViewController. The empty application template was changed to leave these uncommented in recent versions of XCode, but the Beginning iOS Development book you are following used an older version with the stubbed methods pre-commented.

AVAudioPlayer Notification issue

So I'm almost done with my app and I've hit a wall and cannot get around this final problem.
I basically have 2 view's. A main page and the game play screen.
On the first play the game works fine, but when i leave the main screen and then return to the game screen all the sounds are duplicating and firing the the playerItemDidReachEnd early (because I'm guessing there are 2 instances of it, but it cannot seem to get the player to stop this. Here is the basic code causing this. Any help would go a long way, thanks. I'm not sure if my issue is i'm creating multiple instances of View2 in View1 or if I'm creating multiple player objects in view2 thus duplicating the notification.
I know there is a lot going on in my - (void)playerItemDidReachEnd:(NSNotification *)notification, but it works fine on the first load of the page, its only when I click "go back to view1" and then go back in to View2 that the issue happens.
View1ViewController.h
----------------------
#import "(i know here are arrows here, but can't make them show)UIKit/UIKit.h>
#import "ApplicationViewController.h"
#interface MonsterSpellViewController : UIViewController {
}
-(IBAction)showView1;
View2ViewController.m
----------------------
-(IBAction)showView2{
ApplicationViewController *view2 = [[ApplicationViewController alloc]initWithNibName:#"ApplicationViewController" bundle:nil];
view2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:view2 animated:YES];
}
View2ViewController.h
------------------------
#import "(i know here are arrows here, but can't make them show)UIKit/UIKit.h>
#import "(i know here are arrows here, but can't make them show)AVFoundation/AVFoundation.h>
#class AVAudioPlayer;
#interface ApplicationViewController : UIViewController{
AVAudioPlayer *avPlayer;
}
View2ViewController.m
-------------------------
#import "View2ViewController.h"
#synthesize avPlayer;
-(AVAudioPlayer *)avPlayer {
if(!avPlayer) avPlayer = [[AVAudioPlayer alloc]init];
return avPlayer;
}
-(void) viewDidLoad
{
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:avPlayer];
}
-(IBAction)playSoundTest
{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/monster3.mp3", [[NSBundle mainBundle] resourcePath]]];
self.avPlayer = [AVPlayer playerWithURL:url];
[self.avPlayer play];
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
//[player seekToTime:kCMTimeZero];
if (playEscape == YES) {
[self btnEscapeSound];
playEscape = NO;
}
if ((startButton.hidden == NO) && (letterCount != -1) && (playFinal == YES))
{
[self btnFinalSound];
playFinal = NO;
playEscape = YES;
}
NSLog(#"Player Check accessed");
if (letterCount == 3) {
if (Winner == letterCount) {
//moveNextSound = YES;
if (intLoopCount < 104)
{
if (intLoopCount<104) {
[self btnStartOver:intLoopCount];
playFinal = NO;
//intLoopCount++;
}
if (intLoopCount==104) {
startButton.hidden=NO;
playFinal = YES;
}
}
}
}
if (letterCount == 4) {
if (Winner == letterCount) {
//moveNextSound = YES;
if (intLoopCount < 105)
{
[self btnStartOver:intLoopCount];
//intLoopCount++;
if (intLoopCount==105) {
startButton.hidden=NO;
playFinal = YES;
}
}
}
}
}
}
-(IBAction)goBack:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
Try adding [view2 release]; after [self presentModalViewController:view2 animated:YES];

Resources