Implementing searchBarSearchButtonClicked [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How would I implement the searchBarSearchButtonClicked method? I am trying to pass the value of the search bar when the searchBarSearchButtonClicked to a label.

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
yourlabel.text = searchBar.text;
// DO what ever you want
}

Like so:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
_myLabel.text = searchBar.text;
}
That's it!

Related

Xcode 9 TextViewShouldReturn [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
In the past, to dismiss the keyboard after a user hits return I would simply override the TextViewShouldReturn function. However, upon re-downloading Xcode (version 9.3.1) it seems it is no longer a function within UITextViewDelegate and most all previous questions I've found on the subject advise overriding TextViewShouldReturn in some way as well. Is there something I've forgotten or a more efficient way possibly?
This is what I'm currently looking at in my application:
There is no method like textViewShouldReturn() for textView like textField, rather you can use the following code to return your keyboard-
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if(text == "\n") {
textView.resignFirstResponder()
return true
}
return true
}
// Make sure you have self the textView delegate in viewDidLoad method
Maybe you're confusing UITextViewDelegate with UITextFieldDelegate?
There is no function textViewShouldReturn in UITextViewDelegates this function is of UITextField delegate so you have to create your own code for hide keyboard when click on return. By default in UITextView return button is used for next line.
if you want to hide keyboard .try this
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
if ( [ text isEqualToString: #"\n" ] ) {
[ textView resignFirstResponder ];
return NO;
}
return YES;
}

More beautiful way to do if-statement behaviour [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a method in my app that checks to see if some things are true.
- (BOOL)isToggleTurnedOn {
return ([self checkToggleStatus] != [self checkOtherToggle]);
}
When this method returns true, I display a modal.
if ([Preferences isToggleTurnedOn] == true) {
NSArray *welcomeTexts = #[
...
some data
...
];
WelcomeController *welcomeController = [[WelcomeController alloc] initWithText:welcomeTexts];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:whatsNewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
}
Now, this code is not as beautiful as it could by, in my opinion. I'd rather add the presentation of the controller as a parameter of isToggleTurnedOn. What's the best way to refactor this?
- (BOOL)isToggleTurnedOn {
return [self checkToggleStatus] != [self checkOtherToggle]
}
Drives me crazy to see code like this. Be more succinct:
- (BOOL)isToggleTurnedOn {
return ([self checkToggleStatus] != [self checkOtherToggle]);
}

How to hard press button in iPhone and detact 3D touch? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have on Unbutton and i want to open detail page on hard press on it.
so how it possible let me know.
#pragma mark - Previewing delegate
- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
UIViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
detailVC.preferredContentSize = CGSizeMake(0.0, 568.0);
previewingContext.sourceRect = self.btnDetail.frame;
return detailVC;
}
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit{
[self showViewController:viewControllerToCommit sender:self];
}

Show drop down menu when typing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have a UITextField and I would like to create something a bit like the drop down menu in the ios contact app.
When the user starts typing, I would like the menu to drop down. It doesn't really need to limit the data it shows based on what the names but it would be great if it could (ex: it if the user types "m" it only shows strings beginning with m and so on). If the user selects one, that type would be sent to the UITextField where it would be displayed. If there is any open source picker like this, it would be great. If not, is there a way to present something like that that contains all items from the array. This would not have to be complex, it wouldn't have to limit the data shown when the user types or anything.
Response based on this link. Will show you how to get URL values in a dropdown that will autocomplete.
You need to have an NSMutableArray with the possible autocomplete values. In this example, we’ll use an NSMutableArray of pastURLs, and every time the user browses to a URL we’ll add it to the array.
You need to create a UITable to show the values
autocompleteTableView = [[UITableView alloc] initWithFrame:
CGRectMake(0, 80, 320, 120) style:UITableViewStylePlain];
autocompleteTableView.delegate = self;
autocompleteTableView.dataSource = self;
autocompleteTableView.scrollEnabled = YES;
autocompleteTableView.hidden = YES;
[self.view addSubview:autocompleteTableView];
You need to show the table when the field is being edited
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
autocompleteTableView.hidden = NO;
NSString *substring = [NSString stringWithString:textField.text];
substring = [substring stringByReplacingCharactersInRange:range withString:string];
[self searchAutocompleteEntriesWithSubstring:substring];
return YES;
}
And finally only show stuff in the table that is being edited
-(void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
// Put anything that starts with this substring into the autocompleteUrls array
// The items in this array is what will show up in the table view
[autocompleteUrls removeAllObjects];
for(NSString *curString in pastUrls) {
NSRange substringRange = [curString rangeOfString:substring];
if (substringRange.location == 0) {
[autocompleteUrls addObject:curString];
}
}
[autocompleteTableView reloadData];
}
Don't forget to add the proper UITable and UITextfield delegates to your .h file.

Change button title [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i created nine buttons using IBOutletCollection here.
My question is - i want to get title which button is pressed and display it on another buttons title. Is this possible!
Try like this,
- (IBAction)buttonAction:(UIButton *)btn {
yourNextVCobject.buttonTitle = [NSString stringWithFormat:#"%#",btn.titleLabel.text];
// then push to ur vc.
}
In your Next VC,
In .h
#property (nonatomic, retain) NSString *buttonTitle;
In .m
[yourAnotherBtn setTitle:self.buttonTitle forState:UIControlStateNormal];
You can use the below code to set the title of clicked button to targetted another button.
-(IBAction)clickbutton:(id)sender
{
UIButton *firstButton = (UIButton *)sender;
NSString *neededtitle = [NSString stringwithformat:#"%#",firstButton.currentTitle];
[anotherbutton setTitle:neededtitle forState:UIControlStateNormal];
}

Resources