更改视图在标签中加载随机文本

发布于 2024-11-30 09:34:57 字数 131 浏览 3 评论 0原文

我使用 arc4random 命令在三个随机选择的视图之间进行更改。在这三个视图中,我有四个标签,在单击按钮时显示随机文本。因此,当您进入随机视图时,标签为空,直到单击按钮为止。但当进入新视图时,我需要四个不同的标签已经加载了随机文本。我该怎么做?

I'm using the arc4random command to change between three randomly selected views. In those three views, I have four labels displaying random texts when clicking on a button. So the labels are empty when you go to a random view until the button is clicked. But I need the four different labels to already be loaded with the random texts when going to the new view. How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗笺 2024-12-07 09:34:57

在随机选择文件的界面中放入以下代码。

在 view1.h 中

    @interface view1
    {
        NSString *strValue;
        UILabel *lblText;
    }
    @property (nonatomic, retain) NSString *strValue;

在 vi​​ew1.m 中

    @synthesize strValue;
    - (void)viewDidLoad 
    {
         lblText.text = strValue;            
    }

在您的主视图中,您可以通过以下代码调用随机视图集...

    - (void)btnClicked:(id)sender
    {
         view1 *objView1 = [[view1 alloc] initWithNibName:@"view1" bundle:nil];
         objView1.strValue = @"Random Text";
         [self.navigationController pushViewController:objView1 animated:TRUE];
    }

In your interface of randomly selected file put the following code.

In view1.h

    @interface view1
    {
        NSString *strValue;
        UILabel *lblText;
    }
    @property (nonatomic, retain) NSString *strValue;

In view1.m

    @synthesize strValue;
    - (void)viewDidLoad 
    {
         lblText.text = strValue;            
    }

In your main view, from where you are calling the random view set following code...

    - (void)btnClicked:(id)sender
    {
         view1 *objView1 = [[view1 alloc] initWithNibName:@"view1" bundle:nil];
         objView1.strValue = @"Random Text";
         [self.navigationController pushViewController:objView1 animated:TRUE];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文