我正在尝试实现 google map 模块以在添加 mARKER 之前设置控制参数
出路是通过NSBUndles发起获取新的viewController的结果。我的愿望目标是重定向到与预期结果相同的 ViewController。
但是当涉及到实现时,它会加载实际结果:
预期结果: 实际结果
您能否告诉我实例化一个新的 ViewController 并将所有 UI 元素都设置为预期的 viewControllers 的其他细节?我发誓新的 ViewController 已经设置了所有需要的元素?
实际的控制台消息是这样写的:
2014-06-18 17:50:37.766 marker[1469:60b] Text=2014-06-18 17:50:36
2014-06-18 17:50:41.102 marker[1469:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x17daf180>) doesn't contain a view controller with identifier 'SliderViewController''
*** First throw call stack:
(0x3102dfd3 0x3b7dcccf 0x33d1bfb7 0x7e155 0x31031584 0x30f7c0db 0x30f7f873 0x231ffb 0x310300f1 0x30f7f7b8 0x20d6bb 0x138133 0x155319 0x339d000d 0x3387b503 0x33c22af5 0x33842373 0x33840abb 0x30ff92a5 0x30ff6c49 0x30ff6f8b 0x30f61f0f 0x30f61cf3 0x35e66663 0x338ad16d 0x7f4ed 0x3bce9ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
下面是我的代码
-(void) mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate{
sliderVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SliderViewController"];
sliderVC.view.backgroundColor = [UIColor yellowColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:sliderVC animated:YES completion:NULL];
}
仅限新 viewCONtroller (.m) 的代码:
#import "SliderViewController.h"
#import <AudioToolbox/AudioServices.h>
#import "EFCircularSlider.h"
@interface SliderViewController (){
NSString *valueV;
NSString *valueC;
}
@end
@implementation SliderViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_uiSlider.minimumValue = 0.0;
_uiSlider.maximumValue = 100.0;
[_uiSlider removeConstraints:_uiSlider.constraints];
[_uiSlider setTranslatesAutoresizingMaskIntoConstraints:YES];
float value = M_PI * -0.5 ;
_uiSlider.transform = CGAffineTransformMakeRotation(value);
CGRect sliderFrame = CGRectMake(60, 300, 100, 100);
EFCircularSlider* circularSlider = [[EFCircularSlider alloc] initWithFrame:sliderFrame];
[circularSlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:circularSlider];
[circularSlider setCurrentValue:10.0f];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)valueChanged:(EFCircularSlider*)slider {
self.uiValue2.text = [NSString stringWithFormat:@"%.02f", slider.currentValue ];
valueC = self.uiValue2.text;
if(slider.currentValue > 20.0 && slider.currentValue < 30.0 ){
AudioServicesPlaySystemSound(1003);
// AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}
- (IBAction)reset:(id)sender {
[self writeToTextFile:valueV :valueC];
self.uiValue.text =[NSString stringWithFormat:@"%.2f" , 0.00];
[self.uiSlider setValue:0.00];
}
-(void) writeToTextFile:(NSString*) values : (NSString*) values2 {
//get the documents directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/slider.txt",documentsDirectory];
//create content - four lines of text
NSString *content = [NSString stringWithFormat:@"%@%@%@%@", values , @"\n" , values2 , @"\n" ];
//save content to the documents directory
[content writeToFile:fileName
atomically:YES
encoding:NSStringEncodingConversionAllowLossy
error:nil];
NSLog(@"%@",documentsDirectory);
[self displayContent];
}
-(void) displayContent{
//get the documents directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/slider.txt",
documentsDirectory];
NSString *content = [[NSString alloc] initWithContentsOfFile:fileName
usedEncoding:nil
error:nil];
//use simple alert from my library (see previous post for details)
NSLog(@"%@",content);
// [self showEmail:fileName];
}
- (IBAction)sliderChange:(id)sender {
UISlider *slider = (UISlider *)sender;
NSString *newValue = [NSString stringWithFormat:@"%.2f" , slider.value];
self.uiValue.text = newValue;
valueV = self.uiValue.text;
if(slider.value > 30 && slider.value < 50){
AudioServicesPlaySystemSound(1003);
//AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
最佳答案
创建新的 View Controller 时,您必须使用 nib 文件实例化它,例如:
sliderVC = [[SliderViewController alloc] initWithNibName:@"SliderViewController"bundle:nil]
或者如果您使用 Storyboard:
sliderVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SliderViewController"];
否则,没有与您在 Interface Builder 中创建的文件的连接,并且 iOS 不知道要为此 View Controller 加载哪些 UI 元素。
更新:这是您必须设置字符串的地方:
关于iOS 重定向到新的 ViewCONtroller 不会加载所有 UI 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24282011/