Include text with a search - ios

I have a button action that reads off input from a textfield when the user types something, here is the code:
-(IBAction)searchnickname:(id)sender{
[theWebView highlightAllOccurencesOfString: (#"*Nick:", searchText.text)];
}
What I need this to do, is when the user hits this button.. It puts "*Nick:" then whatever the user types after that. I need it to automatically add *Nick: before the string the user enters.
Thank you

I hope this helps:
-(IBAction)searchNickname:(id)sender {
[theWebView highlightAllOccurencesOfString: [#"*Nick:" stringByAppendingString:searchText.text]];
}

Try this...
-(IBAction)searchnickname:(id)sender{
[theWebView highlightAllOccurencesOfString:[NSString stringWithFormat:#"Nick:%#",searchText.text]];
}

Related

parsing UItextfield for incorrect format of entry

I want to get users to enter:
xyz http://www.example.org
in a textfield. But if they enter "http://www.example.org", I want to alert them immediately so they can add the "xyz" part ahead of it.
Whats the best way in Swift (2.x) to do this ? Thanks in advance.
let text = textField.text
if text.hasPrefix("xyz") {
// you're good
} else {
// give alert
}

How can I check if a button is pressed during a specific time interval in iOS?

I'm creating a game for iOS and need some help.
Simply put, random letters will be shown in a label(changing at regular interval), and the user must press the button when they recognise a pattern. If they press the button they earn points, and if they miss it, they lose points.
For example:
let's say they are looking for a letter repeating over one gap. They see the letters "R K W K". On the second K they would press the button. I need to be able to check if the button was pressed while that second K was displayed. I have searched here on stack overflow, but I can't really find anything specific to my situation. Thanks in advance for your responses. I'm new here, so I tried to be as specific as possible.
You can do something like this:
Make a global variable of type bool lets call it isMatch.
While displaying other letters make isMatch = false;
When you display the second 'K' (as your example) make isMatch = true
In you button click method check:
if(isMatch){
point++;
}
else point--;
Make sure you change isMatch = false on displaying other letters.
Hope this helps.. :)
As I understood you are displaying K (say) in UILabel and you might be getting input in UITextField, what you should do is implement ValueChanged IBAction for UITextField and add all letters (K, M, X, H) etc in an array what you have on screen for now. When the text changes it will come in above IBAction, match the UITextField's text with the elements of an array. If there is a match, you are done!
Hope this helps!
Just check in the selector for the button ... (If you're using Interface builder replace void with IBAction)
- (void) buttonWasPressed:(UIButton *) sender {
if ([[[sender titleLabel] text] isEqualToString:#"K"])
point ++;
else
point --;
}
try like this
- (void)buttonTapped:(UIButton *)yourbutton;
{
yourbutton.selected = ![yourbutton isSelected];
}
then this
[self.yourbutton isSelected];

open a link into a clickable label (RTLabel)

Using a RTLabel, I show eficently this html string:
Example Street, 1
as: Example Street, 1. Its clickable, but no action is done. Any RTLabel user Knows how active an action?
Or if there is some altrnative to open in safari that link (in this case to show a map).
Thanks in advance
Set the RTLabel delegate as:
[rtlabel setDelegate:self];
On tapping the link, the below function gets called. Handle accordingly:
-(void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSURL*)url
{
RTLabel * label = (RTLabel*)rtLabel;
[self openBrowserViewForURL:[url absoluteString] pageTitle:label.text];
}

Best method to determine the sender of an event

I have a simple question about event handling in iOS applications... suppose you have an app with some buttons that react to the TouchUpInside event calling the same action, what is the best way within the action method to understand what is the button that triggered the event? I know that it can be easily done using the title of the button, but I think it is not the best way if you have a localized app in which button text may change (unless it is possible to reverse the localization of the title, i.e. retrieve the original string from a localized string)... is there a good practice about this topic? Should I use some other property of buttons to distinguish among different buttons?
Thank you in advance for any help.
There is something called a "Tag" that you can set for UIButtons, or anything that can respond to an event for that matter. If you are using Interface Builder, click the attributes inspector for the item and select a value for the tag (integer). In your code do something like this...
...
- (IBAction)buttonReceived:(id)sender
{
if ([sender tag] == 1) {
//Do something
}
else if ([sender tag] == 2) {
//Do something else
}
}
In addition to the tag property, or just in case you are already using the tag for some other purpose that would mean duplicate tag values for one or more different buttons, you can always set up an IBOutlet ivar to each button you needed to check, and then in the IBAction, do something like this:
- (IBAction)buttonReceived:(UIButton *)sender
{
if (sender == myButtonA) {
// processing for button A
}
else if (sender == myButtonB) {
// processing for button B
}
}
It is a bit more work, but it can come in handy at times.

How to get the return value of viewcontroller & do a NSString compare?

I am a new iOS developer. I am trying to figure out how to take the return value from a viewcontroller and do a string compare to identify the type of viewcontroller. My code will hopefully make this clearer:
I have an instance of a viewcontroller called "
playTimeVC". If I do this:
NSLog(#"hello %#", playTimeVC)
;
I get the following return:
2011-08-20 18:26:33.968 Arrangements[37730:207] hello "<"PlayTimeViewController: 0x58836e0">"
How can I use this return and do some string comparison. ie:
(in Perl)
if ( [playTimeVC] =~ /PlayTimeViewController/) {
// This is the one
}
Another question related to what I am trying to do:
When the user clicks on the home button and they are in a certain viewcontroller, is there any method within that controller that is called or does it go directly to applicationWillResignActive? How about when the user comes back into the app, does it call any method in the VC before resuming?
Thank you in advance.
Eric
The method isKindOfClass of NSObject should suit your needs. You can use it like that:
if ([playTimeVC isKindOfClass: [PlayTimeViewController class]]) {
// do something
}
About your second question. I'm not sure if the viewWillDisappear is called when the user presses the home button. But you can check that by putting an NSLog statement into your viewWillDisappear and check the console.

Resources