Simulate button click in the viewDidLoad - ios

I'm doing an essay app that shows a list of quotes when the user presses a button.
The thing is that when the app is loaded, the UITextView that should show the quotes is empty, and it only gets filled when the button gets tapped.
Is there a way to fill that UITextView? like calling the method that executes when the user taps the button or something like this?
Thanks a lot in advance!

like calling the method that executes when the user taps the button or something like this?
Absolutely. You'll have connected your button to a method that looks something like this:
-(void)buttonPressed:(id)sender
You can call this just as you would any other method:
[self buttonPressed:nil];
I'm passing nil as the sender argument in case you do things to the button in this method.

Related

UITextField and UIButton are not clickable

I am implementing simple UI for URL checking. For this, I used textField and button objects.
When I run the program first time, textField and button will work fine but when I click on the done button on the keyboard then the keyboard is dismissed. Now I want to edit the textField and when I am trying to click on textField it is not clickable or not showing the keyboard. same thing happened to the button, next button is also not clickable.
Here is the code I wrote for the button action
- (IBAction)urlNextButtonAction:(id)sender {
[self.urlTextfield resignFirstResponder];
[SVProgressHUD showWithStatus:#"Verifying URL"];
[self URLValidationMethod];
}
Please check this video you will understand the problem very easily
This is the ViewController screenshot from storyboard
There could be several issue with this..
Check either Textfield delegate might not be or properly set.
Try to debug textfield delegate methods are they working.
it would be helpful if you show what you have written in keyboardShouldReturn method.
It seems like the problem is with the SVProgressHud. You should remove it as soon as you task is completed by calling [SVProgressHud dismiss] or else it will block the UI.

Saving searches from searchBar

I have a UISearchController set up in my table VC and works as expected.
However, I want to be able to save the text from searches (i.e. after they press 'search' or 'enter' on keyboard) into an array.
I couldn't find anything relevant here https://developer.apple.com/documentation/uikit/uisearchbar?language=objc and suspect the solution will involve stuff with the keyboard...
You need to implement searchBarSearchButtonClicked: and/or searchBarTextDidEndEditing: on your searchBar's delegate. These method are called whenever the user presses the search button or finishes editing the text in the search bar, respectively
There is delegate:
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;
Inside this delegate method add searchBar.text into your desired array.

How to reset ViewController on the press of a button in iOS

My app has a ViewController consisting multiple textfield and custom UI elements arranged as a form with "submit" and "reset" buttons.
I want to reset all the textfields and custom UI elements when user clicks the submit button so that user gets a feeling that same Form is opened again.
I tried calling ViewDidLoad() and setNeedsDisplay() on the click of "Submit" button but data previously filled by user remains as it is.
Kindly Help!
Just set the text of all textfields to an empty string (the text value). There is no magic function to clean everything in a view.
The only other solution would be to actually display the ViewController again, but this is probably not what you want, because it causes overhead as well as you might see something of the switching on the screen.
If you programmatically coded your textfields and some other objects, you can refresh always your viewController everytime by adding all your UI codes in the predefined method: -(void)viewWillAppear:(BOOL)animated{} and you should remove all self.view elements by adding this code.
[self.view.subviews makeObjectsPerformSelector:#selector(removeFromSuperview)];
You codes in the viewWillAppear will look like this.
-(void)viewWillAppear:(BOOL)animated{
[self.view.subviews makeObjectsPerformSelector:#selector(removeFromSuperview)];
// Codes for User Interface here
}

How can I post a manufactured event to UIButton

I'm writing a simple iOS 6.1 game. The game involves pressing buttons (OK, it's a tictactoe board, with the cells being UIButtons). The allows the player to choose whether to go first, or whether the computer should go first. If the player tells the computer to go first, I want to set some values, and then fire off the UIButton just as if the user had pressed it.
How can I post an event, or otherwise simulate the action of the button being pressed, to let the rest of the framework do the work of handling the button press?
If there is a better design approach, where I don't have to pretend that the computer has pressed a button, I'm open to hearing about that, instead.
Thank you
Your button will be connected to an action method, typically in your view controller. Just call that method yourself, passing the button as the sender.
Your method will be something like:
-(IBAction)buttonPressed:(UIButton*)sender
{
// Respond to your button press...
}
You'd call it as follows:
[self buttonPressed:self.whicheverButtonYouLike];
You'd need the buttons defined as outlets for this to work.

Send message to a button method w/o pressing the button

Apologies: I may be too tired to be working...
I want to send a message to a button w/o pressing the button. The button has an instance method, defined in the view controller, and properly hooked up and working when the button itself is pressed. The method is "newPuzzle", intended to load a new puzzle when pressed. But I also want to trigger this method during start up, so that a new puzzle is loaded and ready to go, during loadView. So I want to say [?? newPuzzle] in loadView. Am I just missing the proper receiver syntax, or is something more elaborate required to accomplish this? Suggestions, keywords, concepts appreciated.
Check if the IBAction is in the form
( IBAction) newPuzzle:(id) sender
If it is then simply do this to call the function in code(viewWillAppear)
[self newPuzzle:nil]:

Resources