UITextField input and image - ios

I am totally new to programming and Objective C so I am sorry if I sound unclear. I am trying to create an app where the user answers a quiz with input in a text field. When the answer is correct an image for correct answer should appear. It sounds so easy but I do not know how to achieve this and so far I was not able to find tutorial or exact answer to such question. Any help is welcome and I won't give up this early. Thanks.

Try out this tutorial:
http://www.raywenderlich.com/1845/ios-tutorial-how-to-create-a-simple-iphone-app-tutorial-part-2
It shows you how to create a simple app with a text field and image. I'm sure you can piece everything else together.

After user entering text check with the answer if its correct show imageview else show error view
-(IBAction)checkAnswer:(id)sender
{
if([self.answerTextfield.text isEqualtoString:#"xxxxxx"])
{
self.imageView.image = [UIImage imageNamed:#"correct.png"];
[self.view addsubView:self.imageView];
}
else
{
//show error image
}
}

Link has a tutorial on using TextField
http://www.tutorialspoint.com/ios/ios_ui_elements_text_field.htm
customize it according to your needs..
Image can be shown using UIImageView - for this study how to use UIImageView
Hope it helps you to move forward.Try hard

Use this delegate method in "#Natara" 's answer.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if([self.answerTextfield.text isEqualtoString:#"xxxxxx"])
{
self.imageView.image = [UIImage imageNamed:#"correct.png"];
}
else
{
//show error image
}
return NO;
}
This delegate method will be called each time any character is added or deleted. So this mehtod is better option instead of creating a method like "#Yohan" did.
Hope this helps. Cheers :)

Related

Titanium Appcelerator - Remote URL not showing up as background image to View

So here's a nice one. I'm creating a imageView by doing this:
var tagView = Titanium.UI.createImageView({
backgroundImage: 'http://www.travelandtourworld.com/wp-content/uploads/2013/07/google-logo.jpg',
height:150,
width:365,
zIndex:10000
});
The problem is - anytime I use a remote URL as a background image it doesn't show up. Has anyone run into this and is there a good workaround for it?
It's just a rough guess but does it work when you use a normal View instead of an ImageView? Or try the image-property instead of backgroundImage-property for the ImageView. I just think that a background image is not the best practice to do on an ImageView even though the docs say it's possible.
I've done some testing with this as well and also found that backgroundImage doesn't work for remote URLs.
I've sort of fixed it by hacking this code into TiUtils.m of the Appcelerator core (tested with 3.5.0.GA).
if (resultImage == nil) {
if ([image isKindOfClass:[NSString class]]) {
NSURL* imageURL = [TiUtils toURL:image relativeToURL:nil];
resultImage = [[ImageLoader sharedLoader] loadRemote:imageURL];
}
}

iOS Programming:Correcting Text

So I've been developing an iOS application, and one part of it involves the user entering a paragraph of text, and I need my app to filter the text, and use Apple's autocorrect function, to rectify mistakes in the text. For example, if the text is-
The quick brown fox jumpet over the lazy dog
Then it should be able to take the word 'jumpet' and change it to jumped. Does anyone know how this can be done? And I don't have to prompt the user, I'm planning to run this code in a background thread, while an activity indicator spins.
Thanks A Lot!
Raghav
P.S. - The text is in an NSString...
You can manually check spelling in a string using UITextChecker.
I haven't used it myself but it looks pretty straightforward.
Seems Apple doesn't give a public API for autocorrections,
So you should do this with some tricks and hacks.
This article should be useful.
http://blog.persistent.info/2013/10/programmatically-accepting-keyboard.html
Copied From here
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
// Turn spell check on
textView.autocorrectionType = UITextAutocorrectionTypeYes;
return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
// Turn spell check off and clean up red squiggles.
textView.autocorrectionType = UITextAutocorrectionTypeNo;
NSString *currentText = textView.text;
textView.text = #"";
textView.text = currentText;
return YES;
}

Create dynamic cell with link.

I'm developing application similar to Vine Application, in that comment cell is giving navigation (#User is there or #tag is there) that is exactly working if user or tag is there otherwise not.
If anyone know, how to do that please give me reference or suggestion (Please don't give any suggestion like if word found with # or # then give string attribute that I already done that but I want exactly vice comment cell )
You can give some idea or suggestion also.
Thanks is advance.
You can use TTTAttributedLabel. It will help you to provide link action.
Implement it as follows
TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:frame];
[label setAttributedText:#"yourText"];
label.delegate = self;
label.enabledTextCheckingTypes = NSTextCheckingTypeLink;
[label addLinkToURL:url withRange:range];
[yourCell.contentView addSubview:label];
and you can capture the link action in:
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url
which is the TTTAttributedLabelDelegate method. Don't forget to add TTTAttributedLabelDelegate in the interface file.

Reloading a non-table view (iOS)

I'm working on a painting app, and I want to user to be able to switch through paintings that are saved as PNGs to the documents directory. I've made an IBAction that does this:
-(IBAction)switchPage:(id)sender{
if ([sender tag] ==1)
{
currentImage=currentImage-1;
}
else
{
currentImage++;
}
[[NSUserDefaults standardUserDefaults] setInteger:currentImage forKey:#"currentDoc"];
[self.view setNeedsDisplay];
}
Just to let you know, I have 2 buttons, a back and forward, and they're connected to the same IBAction that's pasted above. The back button has a tag of 1, and the forward button doesn't have a tag. currentImage is an int that is used to set an image's name, so if currentImage =1, then it would set the image to image1. But that's not what I'm having trouble with, I'm having trouble "reloading" the view. I'm using setNeedsDisplay, but it's not working, and I know that reloadData is only for UITables, so what else could I use?
I've been searching for an answer, but none of the existing questions about this don't have a clear answer, or are under different circumstances.
Thanks for your time and/or dealing with a stupid question, as I'm new to Xcode.
-Karl
I see no view code in your post.
Assuming you have a UIImageView that is displaying the image you would just do:
myImageView.image = whateverUIImage;

How do I disable a UIButton?

I am working on a project in which I have to show all photos of Photo Library in a plist and show them horizontally on UIButtons.
My app will also have an edit button: when the user clicks this button, a delete mark (such as usually appears in other iPhone/iPad apps) should show on each button.
But here's the crucial bit: as soon as this delete mark appears, the functionality of the button should be disabled. I've tried accomplishing this with the following:
{
editbutton.enabled=NO;
}
...but it neither produces an error nor works. What should I do?
Please set this...
editButton.userInteractionEnabled = NO;
or You can use
editButton.enabled = NO;
Swift 3 and above
editButton.isEnabled = false
setEnabled is now part of the setter method for isEnabled.
setter for property enabled is overridden in class UIButton. try to send a message.
[editbutton setEnabled:NO];
Use the enabled property of UIControl which the super class of UIButton and set it with NO.
myButton.enabled = NO;
You could also try as #Marvin suggested,
In that case your button will not respond to any touch event from user,
In addition to the above:
Set
editButton.userInteractionEnabled = NO;
or you can use
editButton.enabled = NO;
You might want to gray out the button so the user knows it was disabled:
editButton.alpha = 0.66
yourBtn.userInteractionEnabled = NO;

Resources