I'm trying to pass a NSMutableString through a segue.
The mutableString is a title from an MKPolygon.
I've done the mutableString like this: self.titleString = [[NSMutableString alloc] initWithString:polygon.title];
I'm not sure how to segue the String:
I've got this now:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"PickerViewController"])
{
NSLog(@"delegated");
//Get the new view controller using [segue destinationViewController].
PickerViewController *vc =[segue destinationViewController];
vc.titleString = titleString;
}
}
I get an error with vc.titleString = titleString;
. Not sure how to set the String in the PickerViewController segue.
Error: Property 'titleString' not found on object of type 'PickerViewController *'
The PerformSegueWithIdentifier is this Method:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//this would be the yes button or cancel
if (buttonIndex == 0 ){
NSLog(@"ButtonIndex Okay");
}
if (buttonIndex == 1) {
[self performSegueWithIdentifier:@"PickerViewController" sender:self];
}
}
I do know how to segue an object, but with Strings I don't get my mind to it.
Help would be really appreciated!
Update 1:
- I've imported the
PickerViewController.h
in the ViewController.h
file.
- I've changed the
vc.titleString = titleString;
with vc.titleString = self.titleString;
- I've added a
@property (strong,nonatomic) NSMutableString *titleString;
to the PickerViewController.h
No luck.
Update 2:
- Tried an other way to segue the String:
[(PickerViewController *)[segue destinationViewController] setTitleString:self.titleString];
Got the error: No visible @interface for 'PickerViewController' declares the selector 'setTitleString:'
ViewController.h file:
@property (strong, nonatomic) NSMutableString *titleString;
ViewController.m file:
@synthesize titleString;
self.titleString = [[NSMutableString alloc]init];
PickerViewController.h file:
@property (strong, nonatomic) NSMutableString *titleString;
PickerViewController.m file:
@synthesize titleString;
self.titleString = [[NSMutableString alloc]init];
Still seems like it doesn't recognises the titleString
.
Update 3:
Still no luck with segueing the string.
Maybe it has something to with this:
The NSMutableString is being used in a loop. The loop checks if there is an GPS, annotation or a touch is inside a MKPolygon. Each polygon has it's own color, which is named in the polygon.title: See code below*. So the String saves the 'selected' polygon title. See the loop below:
One of the Polygons:
CLLocationCoordinate2D roodPoly[2];
roodPoly[0] = CLLocationCoordinate2DMake(52.372445351278294, 4.876454472541809);
roodPoly[1] = CLLocationCoordinate2DMake(52.37288748990477, 4.878369569778442);
MKPolygon *roodpoly = [MKPolygon polygonWithCoordinates:roodPoly count:2];
roodpoly.title = @"red";
[myMapView addOverlay:roodpoly];
A little bit of the loop:
if(CGPathContainsPoint(mpr , NULL, mapPointAsCGP, FALSE)){
NSLog(@"Coordinate %f,%f is in polygon %@", tapCoord.latitude, tapCoord.longitude, polygon.title);
self.titleString = [[NSMutableString alloc] initWithString:polygon.title];
self.subtitleString = [[NSMutableString alloc] initWithString:polygon.subtitle];
alertView = [[UIAlertView alloc]initWithTitle:@"Found it" message:subtitleString delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Stel notificatie in", nil];
[alertView show];
NSLog(@"The color of the Polygram is: %@", titleString);
}
CGPathRelease(mpr);
}
}
}
I thought this could cause the problem for not finding the String :(