我试图通过segue传递NSMutableString。
mutableString是MKPolygon的标题。
我已经完成了像这样的mutableString:self.titleString = [[NSMutableString alloc] initWithString:polygon.title];
我不确定如何区分字符串: 我现在有了这个:
-(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;
}
}
我在vc.titleString = titleString;
时遇到错误。不知道如何在PickerViewController segue中设置String。
错误:Property 'titleString' not found on object of type 'PickerViewController *'
PerformSegueWithIdentifier就是这个方法:
- (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];
}
}
我确实知道如何设置一个物体,但是对于弦乐,我不会理解它。 帮助将非常感谢!
更新1:
PickerViewController.h
文件中的ViewController.h
。vc.titleString = titleString;
vc.titleString = self.titleString;
@property (strong,nonatomic) NSMutableString *titleString;
添加到PickerViewController.h
没有运气。
更新2:
[(PickerViewController *)[segue destinationViewController] setTitleString:self.titleString];
得到错误:No visible @interface for 'PickerViewController' declares the selector 'setTitleString:'
ViewController.h文件:
@property (strong, nonatomic) NSMutableString *titleString;
ViewController.m文件:
@synthesize titleString;
self.titleString = [[NSMutableString alloc]init];
PickerViewController.h文件:
@property (strong, nonatomic) NSMutableString *titleString;
PickerViewController.m文件:
@synthesize titleString;
self.titleString = [[NSMutableString alloc]init];
似乎还没有认出titleString
。
更新3:
仍然没有运气的字符串。
也许它与此有关:
NSMutableString正在循环中使用。循环检查是否有GPS,注释或触摸在MKPolygon内。每个多边形都有自己的颜色,在polygon.title中命名:见下面的代码*。所以String保存了所选的'多边形标题。请参阅下面的循环:
其中一个多边形:
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];
一点循环:
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);
}
}
}
我认为这可能会导致找不到字符串的问题:(
答案 0 :(得分:1)
在你的" PickerViewController.h"应该是这样的:
#import <UIKit/UIKit.h>
@interface PickerViewController : UIViewController
@property (strong,nonatomic) NSMutableString * titleString;
@end
在你的&#34; ViewController.m&#34;文件:
#import "ViewController.h"
#import "PickerViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
[(PickerViewController *) [segue destinationViewController] setTitleString:self.titleString];
}
@end
这里工作正常..
希望有所帮助:)