【问题标题】:Refresh/reload textview from database | Button Tapped Function从数据库刷新/重新加载 textview |按键功能
【发布时间】:2015-04-16 08:37:06
【问题描述】:

我已经声明了 textview 出口:

@IBOutlet weak var messageView: UITextView!

我已经创建了界面动作,并放置了逻辑:

@IBAction func refreshTextViewTapped(sender: UIButton) {

// logic

}

使用新内容重新加载/更新 textview。

【问题讨论】:

    标签: ios database textview refresh reload


    【解决方案1】:

    setText 函数不会自动更新 textview 吗?如果文本已经被更新,你需要一个重新加载函数来做什么?

    - (void)viewDidLoad()
    {
        setMyTextView();
    
        // create the button that calls your function to update the text view
        UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 44);
        [myButton addTarget:self action:@selector(setMyTextView) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:myButton];
    }
    
    - (void)setMyTextView()
    {
        NSString *myText = // value that is returned from the database query;
        [self.myTextView setText:myText];
    }
    

    【讨论】:

    • 您是使用 SQLite 之类的本地数据库还是连接到服务器?在任何一种情况下,您都可以创建一个连接到数据库的函数,查询信息,然后在 textview 上调用 setText 函数。
    • 我只是没有记住 iOS/Xcode 中可用的所有方法、函数和属性,所以我仍在学习所有文档。
    • 我添加了一个代码示例...让我知道这是否有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 2011-01-01
    • 2014-07-01
    • 2012-07-31
    • 2011-11-29
    相关资源
    最近更新 更多