Search code examples
iosdatabasetextviewrefreshreload

Refresh/reload textview from database | Button Tapped Function


I have declare the textview outlet:

@IBOutlet weak var messageView: UITextView!

I have created the interface action, and place the logic:

@IBAction func refreshTextViewTapped(sender: UIButton) {

// logic

}

Reload/update textview with new content.


Solution

  • doesn't the setText function automatically update the textview? What would you need a reload function to do if the text is already being updated?

    - (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];
    }