Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS重定向到新ViewCOntroller不会加载所有UI元素_Ios_Objective C_Uiviewcontroller - Fatal编程技术网

iOS重定向到新ViewCOntroller不会加载所有UI元素

iOS重定向到新ViewCOntroller不会加载所有UI元素,ios,objective-c,uiviewcontroller,Ios,Objective C,Uiviewcontroller,我正在尝试实现GoogleMap模块,以便在添加标记之前设置控制参数 解决方法是通过NSBundle启动获取新viewController的结果。我的目标是按照预期结果重定向到sameViewController 但在实现时,它会加载实际结果: 预期结果: 实际结果 请告诉我实例化一个新的ViewController,并将所有UI元素设置为预期的ViewController的其他详细信息,好吗?我发誓,新的ViewController已启用所有必需元素 实际控制台消息写入: 2014-06-1

我正在尝试实现GoogleMap模块,以便在添加标记之前设置控制参数

解决方法是通过NSBundle启动获取新viewController的结果。我的目标是按照预期结果重定向到sameViewController

但在实现时,它会加载实际结果:

预期结果: 实际结果

请告诉我实例化一个新的ViewController,并将所有UI元素设置为预期的ViewController的其他详细信息,好吗?我发誓,新的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) 
仅适用于新viewCOntroller(.m)的代码:

#导入“SliderViewController.h”
#进口
#导入“EFCircularSlider.h”
@接口SliderViewController(){
NSString*valueV;
NSString*valueC;
}
@结束
@实现SliderViewController
-(无效)viewDidLoad
{
[超级视图下载];
_uiSlider.minimumValue=0.0;
_uiSlider.maximumValue=100.0;
[\u uiSlider removeConstraints:\u uiSlider.constraints];
[\u uiSlider SetTranslates自动调整大小GMaskintoConstraints:是];
浮动值=M_PI*-0.5;
_uiSlider.transform=CGAffineTransformMakeRotation(值);
CGRect sliderFrame=CGRectMake(60300100100);
EFCircularSlider*circularSlider=[[EFCircularSlider alloc]initWithFrame:sliderFrame];
[circularSlider addTarget:self action:@selector(valueChanged:)for ControlEvents:UIControlEventValueChanged];
[self.view addSubview:circularSlider];
[循环滑块设置电流值:10.0f];
//加载视图后执行任何其他设置。
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(无效)值已更改:(EFCircularSlider*)滑块{
self.uiValue2.text=[NSString stringWithFormat:@“%.02f”,slider.currentValue];
valueC=self.uiValue2.text;
如果(slider.currentValue>20.0&&slider.currentValue<30.0){
AudioServicesPlaySystemSound(1003);
//AudioServicesPlayAlertSound(KSystemsSoundId_振动);
AudioServicesPlaySystemSound(kSystemSoundID_振动);
}
}
-(iAction)重置:(id)发送方{
[自写文本文件:valueV:valueC];
self.uiValue.text=[NSString stringWithFormat:@“%.2f”,0.00];
[self.uiSlider设置值:0.00];
}
-(无效)writeToTextFile:(NSString*)值:(NSString*)值2{
//获取文档目录:
NSArray*path=NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory,NSUserDomainMask,是);
NSString*documentsDirectory=[paths objectAtIndex:0];
//使用documents目录创建要将数据写入的文件名:
NSString*文件名=[NSString stringWithFormat:@“%@/slider.txt”,documentsDirectory];
//创建内容-四行文本
NSString*内容=[NSString stringWithFormat:@“%@%@%@%@@”,值、@“\n”、值2、@“\n”];
//将内容保存到文档目录
[内容写入文件:文件名
原子论:是的
编码:NSStringEncodingConversionLowlossy
错误:无];
NSLog(@“%@”,文档目录);
[自显示内容];
}
-(无效)显示内容{
//获取文档目录:
NSArray*path=NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory,NSUserDomainMask,是);
NSString*documentsDirectory=[paths objectAtIndex:0];
//使用documents目录创建要将数据写入的文件名:
NSString*文件名=[NSString stringWithFormat:@“%@/slider.txt”,
文件目录];
NSString*content=[[NSString alloc]initWithContentsOfFile:fileName
usedEncoding:无
错误:无];
//使用我的库中的简单警报(有关详细信息,请参阅上一篇文章)
NSLog(@“%@”,内容);
//[自我展示电子邮件:文件名];
}
-(iAction)滑块更改:(id)发送方{
UISlider*滑块=(UISlider*)发送器;
NSString*newValue=[NSString stringWithFormat:@“%.2f”,slider.value];
self.uiValue.text=newValue;
valueV=self.uiValue.text;
如果(slider.value>30&&slider.value<50){
AudioServicesPlaySystemSound(1003);
//AudioServicesPlayAlertSound(KSystemsSoundId_振动);
AudioServicesPlaySystemSound(kSystemSoundID_振动);
}
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回(interfaceOrientation!=UIInterfaceOrientation肖像向上向下);
}
@结束

创建新视图控制器时,必须使用nib文件对其进行实例化,例如:

sliderVC=[[SliderViewController alloc]initWithNibName:@“SliderViewController”捆绑包:nil]

或者,如果您使用故事板:

sliderVC=[self.storyboard实例化eviewcontrollerwhiteIdentifier:@“slidervontroller”]

否则,将无法连接到您在Interface Builder中创建的文件,并且iOS不知道要为此视图控制器加载哪些UI元素

更新:这是您必须设置字符串的地方:


添加到@Nikolas Burk answer-如果您的所有ViewController都在一个故事板上,您可以像下面这样实例化它们:

MyClassViewController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"name"];

名称
在InterfaceBuilder中设置。

代码编辑它显示以下异常,即序列图像板()不包含标识符为“SliderViewController”的视图控制器是,您需要使用在此视图控制器的序列图像板中设置的标识符,而不是字符串SliderViewController您的意思是在该视图控制器的标识下设置序列图像板ID吗?
#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
MyClassViewController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"name"];