ios - 从一个 View Controller 传递字符串并将其显示在 ios 的 UITextView 中

标签 ios objective-c

我已经尝试了一切可以做的事情来解决这个问题,因为我是新手,我没有得到明确的答案。 我有两个 View Controller 。我将textview的数据传递给第二个 Controller 并将其显示在UILabel中,没有问题。但现在我必须再次将标签文本发送到同一个 TextView 进行编辑。问题是,当我双击标签时,它会将我导航到第一个 View ,但不会在 TextView 中显示文本。

-(void)AddTextToCanvasWithGesture:(UITextView*)takenText
{

    CGRect rect = CGRectMake(35, 60,takenText.contentSize.width,takenText.contentSize.height);

    UIView *holderView = [[UIView alloc] initWithFrame:rect];

    rect.origin.x=0;
    rect.origin.y=0;
    UILabel *textLabel=[[UILabel alloc]initWithFrame:rect];


    [textLabel setText:takenText.text];
     self.text=takenText.text;

    [textLabel setTextColor:takenText.textColor];
    [textLabel setFont:[UIFont fontWithName:takenText.font.fontName size:takenText.font.pointSize]];
    [textLabel setNumberOfLines:0];
    [textLabel sizeToFit];
    [holderView setTag:1];
    [textLabel setTag:1+1];
    [holderView addSubview:textLabel];


    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];

    [tapRecognizer setNumberOfTapsRequired:1];
    [tapRecognizer setDelegate:self];

    [holderView addGestureRecognizer:tapRecognizer];



    tapRecognizer = nil;

    UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(LaunchText)];

    [doubleTapRecognizer setNumberOfTapsRequired:2];
    [doubleTapRecognizer setDelegate:self];


    [holderView addGestureRecognizer:doubleTapRecognizer];
    holderView.userInteractionEnabled=YES;


    [tapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer]; 

}

我必须将此标签的文本发送到第二 View Controller 的 TextView

-(void) LaunchText{

    [self update:self.text];
      [self performSegueWithIdentifier:@"textAdd" sender:self]; 
}

-(void)update:(NSString*)string{

    TextAddViewController *txt=[[TextAddViewController alloc]init];

    txt.usingText.text=string;
}

我在第二个 View 中获取这个字符串

-(void)viewDidLoad
{
    [super viewDidLoad];

    ViewController *vm=[[ViewController alloc]init];
    self.usingText.text=vm.text;
}

最佳答案

SecondViewController 中重写以下方法,并将 UILabel 值传递给 FirstViewController

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"prepareForSegue is called");
    if ([[segue identifier] isEqualToString:@"CONTROLLER_SEGUE"])  {

        TextAddViewController *vc = [segue destinationViewController];
        [vc.usgingText setText:@"SOME TEXT"];
    }
}

关于ios - 从一个 View Controller 传递字符串并将其显示在 ios 的 UITextView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26418648/

相关文章:

ios - 苹果手机 : How do I add a text view that the font size decreases to fit text view size when needed to

ios - 如何通过点击按钮滚动到 ScrollView 中的特定 View ?

objective-c - 使用 Group By Count 获取核心数据属性

iphone - 获取NSArray中xcode项目文件夹的所有图像

ios - WebRTC' 不包含位码 您必须在启用位码的情况下重建它(Xcode 设置 ENABLE_BITCODE)

objective-c - UIViewController 的 View 有奇怪的 20px y 边距

javascript - 如何在 iPad 上使用 JavaScript/Obj-C 将图像保存到照片库?

直方图或包数据结构的 Objective-C 实现

ios - didRegisterForRemoteNotificationsWithDeviceToken 在 ios8 中未调用,但 didRegister...Settings 是

ios - Cocos2d iPhone v3.0 - 向上滑动执行 Action