Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
NSString始终传递空iOS_Ios_Objective C_Null_Nsstring_Viewcontroller - Fatal编程技术网

NSString始终传递空iOS

NSString始终传递空iOS,ios,objective-c,null,nsstring,viewcontroller,Ios,Objective C,Null,Nsstring,Viewcontroller,我有一个quick.vc,我将一个NSString从一个vc传递到另一个,它传递null。(我正在使用UITextView) 它在运行时总是记录为空?我已经尝试了很多方法! 关于如何传递字符串而不为null,有什么想法吗 谢谢你的错误 selectFriendsViewController *sfvc = [[selectFriendsViewController alloc] init]; sfvc.string = self.userText; 这将创建一个新的selectFrie

我有一个quick.vc,我将一个NSString从一个vc传递到另一个,它传递null。(我正在使用UITextView)

它在运行时总是记录为空?我已经尝试了很多方法! 关于如何传递字符串而不为null,有什么想法吗

谢谢你的错误

  selectFriendsViewController *sfvc = [[selectFriendsViewController alloc] init];
  sfvc.string = self.userText;
这将创建一个新的
selectFriendsViewController
实例,但您不使用它。该方法完成后,它将被解除分配。因此,您什么都没有得到

如果在
iAction
中触发一个序列,请使用
prepareforsgue
传递数据

编辑, 如果你在点击按钮时发射了一个segue

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.destinationViewController isKindOfClass:[selectFriendsViewController class]]) {
    selectFriendsViewController * dvc = (selectFriendsViewController*)segue.destinationViewController;
    dvc.string = self.textField.text;
}
}

我认为您无法导航并将值推送到下一个viewController 如果使用xib文件,请使用此代码

- (IBAction)next:(id)sender {
    selectFriendsViewController *sfvc = [[selectFriendsViewController alloc] init];
    sfvc.string = self.textField.text;

[self.navigationController pushViewController:sfvc animated:YES];

}

希望该代码对您有所帮助。

如果您不想显示null,请使用下面的代码

  #pragma mark - check string is empty or not

   - (IBAction)next:(id)sender 
    {

        self.userText = self.textField.text;
        selectFriendsViewController *sfvc = [[selectFriendsViewController alloc] init];
        sfvc.string = [self checkEmpty:self.userText];
    }

  - (void)checkEmpty:(NSString *)check
   {
     @try 
     {
       if (check.length==0)
         check = @" ";
       if([check isEqual:[NSNull null]])
         check = @" ";
     }
     @catch (NSException *exception) 
     {
       check = @" ";
     }
   }

你“连接”了吗InterfaceBuilder中的textField outlet?是的,我看到了我对ios开发不熟悉的连接可能的副本,你能帮我一下吗?你在方法
next
中启动了一个segue吗?我以前没有使用seque方法发送数据谢谢leo,当我按下next时,我如何将此方法放入iAction以传递它按钮“在其他情况下”是什么意思?
  #pragma mark - check string is empty or not

   - (IBAction)next:(id)sender 
    {

        self.userText = self.textField.text;
        selectFriendsViewController *sfvc = [[selectFriendsViewController alloc] init];
        sfvc.string = [self checkEmpty:self.userText];
    }

  - (void)checkEmpty:(NSString *)check
   {
     @try 
     {
       if (check.length==0)
         check = @" ";
       if([check isEqual:[NSNull null]])
         check = @" ";
     }
     @catch (NSException *exception) 
     {
       check = @" ";
     }
   }