Using Text Field and Text View Controls in iPhone

One common problem that arises when using UITextField and UITextView controls in iPhone (or iPad)
programming is that of dismissing the keyboard when text entry is complete. In this blog, we’ll show
you how this is done.

Start Xcode, and choose “Create a new Xcode project.” Choose the Single View Application template,
and click Next. Name the project “TextControls” and choose options as shown below:

Click Next, choose a location to save the app, then click Create. Select the MainStoryboard.storyboard
file in the Project Navigator. If you wish, adjust the color of the view by changing the background color
in the Attribute Inspector.

Drag a a Text Field and a Text View to the view as shown on the following page. Delete the text in the
Text View control. The screen shot shows this text selected prior to deleting it.

Change the value of the Return Key attribute to Done in the Attribute inspector for the Text Field, as
shown below:

Text Field controls are able to send an Event called “Did End On Exit” that is fired when the Done key
is pressed on the keyboard. Text Views do not have this event, we must make some other provision for
dismissing the keyboard. We’ll deal with the Text Field now, and come back to deal with the Text View
in just a bit.

The next task is to write an action method to respond to the Text Field’s Did End On Exit method.
Select the file ViewController.h in the Project Navigator, and make the bolded changes in the following
listing:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

–(IBAction)dismissKeyboard:(UITextField *)sender;

@end

Now, open the ViewController.m file, and add the method definition to it:

#import "ViewController.h"

@interface ViewController ()
@end
@implementation ViewController

–(IBAction)dismissKeyboard:(UITextField *)sender
{
[sender resignFirstResponder];
}

–(void)viewDidLoad
{
[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}
…

Return to the MainStoryboard.storyboard file, and right click the View Controller object. Click and
drag from the circle to the right of the dismissKeyboard method to the TextField. When the popup
comes up, select Did End On Exit from the list of available events.

<img src="http://www.edumobile.org/iphone/wp-content/uploads/2012/05/WireUpMethod-300×108.png" alt="" title="WireUpMethod" width="450" height="160

In the dismissKeyboard method, we are calling a method “resignFirstResponder” on the UITextField.
This method tells the text field to stop being the first responder for events sent to the window. When the
text field gives up its first responder status, its interface (the keyboard) is released and goes away.

Let’s run the app. In this test, since we haven’t done anything with the UITextView as yet, we will only
interact with the text field control. Click on the text field. The keyboard will display:

When we click on the text field, we give it focus, and make it the first responder of the view it is in. As soon as a text
control gains first responder status, it displays the keyboard for text entry.

At this point, the responder chain looks something like
this:

Events “bubble up” the responder chain to be handled by the first responder in the chain that has an
event handler for the event. In the case of the text field, it can (at this point) handle two events: the tap
of a key on the keyboard (which is built-in) and the dismissKeyboard event (which we defined and
wired up in Interface builder). Verify that the text field is handling keyboard taps by entering some text
via the software keyboard. As you enter text, it will appear in the text field control. When you are
finished, tap the “Done” button on the software keyboard. This will send the Did End On Exit event to
the ViewController, which will handle the event using the dismissKeyboard method.

Now, let’s stop the running app, and learn how to handle the text view control.

Since UITextView is unable to send the Did End On Exit event, we must dismiss its keyboard a
different way. The usual method is to use a button. But there are two ways to set the button up,
depending on what we want the user experience to be.

If we want to indicate to the user that the app will do something with the text in the UITextView (such
as saving it or sending it to a web service of some sort), we should put a visible button on the view, and
wire it up to an action method that resigns the first responder on the text view control. This is the
approach we’ll take now.

In ViewController.h, add the bolded lines:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic, strong) IBOutlet UITextView *textView;

–(IBAction)dismissKeyboard:(UITextField *)sender;

–(IBAction)saveButtonClicked:(UIButton *)sender;

@end

Synthesize the textView property and write the method definition in ViewController.m:

#import "ViewController.h"

@interface ViewController ()
@end
@implementation ViewController

@synthesize textView;

–(IBAction)dismissKeyboard:(UITextField *)sender
{
[sender resignFirstResponder];
}

–(IBAction)saveButtonClicked:(UIButton *)sender
{

// save the text in the text view here…
// then dismiss the keyboard:

[self.textView resignFirstResponder];
}

–(void)viewDidLoad
…

We’re not showing how to actually save the text here. As far as dismissing the keyboard, the approach
is exactly the same: we’re telling the text view control to resign its first responder status. This is why
we need the property defined on the UITextView.

Open up the MainStoryboard.storyboard file, drag a button to the view, and give it the title “Save” as
shown:

Right click the new button, and drag from the circle to the right of the Touch Up Inside event to the View Controller
object. The saveButtonClicked action will be shown; click it to wire up the event with the method that will handle it.

Now, right click the View Controller object, and drag from the circle to the right of the textView outlet to the text
view object on the view. This will wire the textView property to the actual UITextView object in the view.

Now run the app again and test both the UITextField and UITextView to make sure that they can both dismiss the
keyboard. Clicking the Done key while editing in the text field will dismiss the keyboard as before. To dismiss the keyboard while editing in the text view, simply click the “Save” button.

Another way to use a button to dismiss the keyboard from a text view is often seen. In this method,
touching anywhere on the screen outside of the text controls or keyboard will dismiss the view. This
method involves a trick – we’re going to change the type of the Save button, expand it to fill the view,
and send it to the back of the control stack. Ready? Let’s do it!

First, using the drag handles of the save button, expand it so that it fills the entire view. After this step,
the interface will look like this:

The second step is to send the button to the back of the list of controls on the view. Just grab the button
in the View Controller Scene panel, and move it up to the top of the list of controls in the view:

Since controls are painted on the view in the order they are shown in this list, putting the button on top of the list will send it behind all other controls in the window.

The third step is to delete the title from the button. This can be done either by double – clicking the title on the button and deleting it, or by deleting the title directly in the Attributes inspector panel while the button is selected. Do this now.

The last step is to change the type of the button in the Attributes inspector panel to “Custom” as shown
here:

After this change is made, the button will change to a transparent color, so the underlying view color is
displayed.

Run the program again. This time, touching anywhere in the background will dismiss the keyboard
from the UITextView control.

Apple wants courtroom cleared while Steve Jobs deposition is played

Universal Music Group is embroiled in a few lawsuits involving money owed to producers and artists, and in the course of events depositions by Eddy Cue and Steve Jobs were recorded at some point. Now, as these cases near trial, Apple is seeking a modification to a protective order to keep those depositions from being seen by anyone outside the courtroom — primarily, musicians.

While this may sound nefarious, the fact is that previously the court was willing to clear the courtroom (of UMG employees, too) when reviewing these depositions. Apple claims the release of documents that may include discussions between it and record labels would prove materially damaging to its business (iTunes) — and I’m inclined to agree. While it would no doubt clue musicians in to some interesting tidbits, the fact is that those negotiations were private for a reason. The Jobs and Cue depositions, likely having discussed those negotiations, are similarly in need of protection, lest Apple’s competitors know exactly where Apple stands with its groundbreaking iTunes Music Store and record labels.

Apple wants courtroom cleared while Steve Jobs deposition is played originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 20:45:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Judge Richard A. Posner scolds Apple’s lawyers

Well-known Circuit Court Judge Richard A. Posner told Apple’s lawyers that he is tired of the company’s courtroom antics in its patent dispute with Motorola. According to a report in FOSS Patents, Posner writes in a recent order, “I’ve had my fill of frivolous filings by Apple. The next such motion, and I shall forbid it to file any motions without first moving for leave to file.”

FOSS Patents provides some insight into the back and forth that led to this harsh rebuke of Apple. In a nutshell, Apple is trying to block Motorola from deposing a particular expert by bringing up the same motion again, after it was denied the first time. Supposedly, the company is also pushing the issue so quickly that Motorola isn’t able to adequately respond.

Posner is overseeing the lawsuit in the United States District Court for the Northern District of Illinois.

Judge Richard A. Posner scolds Apple’s lawyers originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 17:15:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Apple updates iPhoto, iMovie, GarageBand for iOS

Apple just pushed a series of updates for its iLife iOS apps. The iPhoto 1.0.1 update doesn’t add any new features, but does offer a number of stability improvements including when publishing a journal to iCloud, the URL of the journal can now be copied using a Copy Link button. It also addresses an issue that could cause duplicate photos to appear in Photos view. iPhoto for iOS was first released at the beginning of March and in only 10 days hit one million downloads.

GarageBand 1.2.1 fixes an issue that could lead to crashing or missing songs when sharing to iCloud, resolves an error when logging into SoundCloud using a Facebook account, and addresses minor issues related to performance and stability.

iMovie 1.3.1 squashes a number of bugs, including problems accessing Help on iPad. There’s also a new feature too: now you can easily send a song from GarageBand to iMovie.

Apple also pushed another update to its Cards app. The 1.1.2 update doesn’t address any noted issues that weren’t already listed in the previous two updates to the app in April.

iPhoto, GarageBand, and iMovie are $4.99 each and Cards is a free download.

Apple updates iPhoto, iMovie, GarageBand for iOS originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 16:45:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Daily Update for May 1, 2012

It’s the TUAW Daily Update, your source for Apple news in a convenient audio format. You’ll get all the top Apple stories of the day in three to five minutes for a quick review of what’s happening in the Apple world.

You can listen to today’s Apple stories by clicking the inline player (requires Flash) or the non-Flash link below. To subscribe to the podcast for daily listening through iTunes, click here.

No Flash? Click here to listen.

Subscribe via RSS

Daily Update for May 1, 2012 originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 16:25:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Research: Walmart sold 1.3 million iPads in March quarter

Image

While in many minds the term Walmart has the connotation of low prices on “stuff” ranging from tires to baby clothing, some new research from Consumer Intelligence Research Partners (CIRP) shows that the discount retailer is an increasingly important part of Apple’s overall distribution efforts.

Business Insider notes that Tim Cook highlighted Walmart during the recent earnings call, saying that the company is “an increasingly more substantial partner in the iPad space… and an evolving partner on iPhone. And so we’re working with them and enjoy working with them and hope to continue expanding.”

How much of a partner is Walmart? The company sold 1.3 million iPads in the quarter ending March 30, 2012, which means that the company sells 11 percent of all iPads. The only bigger retailers are Apple itself (with a 26 percent share of sales) and Best Buy (24 percent).

While Walmart has the distribution channel to help Apple sell a lot of iPads, CIRP pointed out that this drives down the average selling price of the devices to that Walmart can make a “reasonable gross profit.” In the long run, that may be a downside to Apple.

Research: Walmart sold 1.3 million iPads in March quarter originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 15:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Apple may not market "4G" iPad in the UK

In Australia, Sweden and, now, the UK, Apple is facing opposition over its use of 4G in the iPad name. According to GigaOM, The UK Advertising Standards Authority will release an adjudication on Wednesday that could lead to a new investigation into whether Apple is misleading customers when it says the iPad delivers 4G speeds. This adjudication is a response to 40 complaints received by the standards body from people who were confused by the 4G label, as the UK doesn’t have a 4G wireless carrier.

When approached by the ASA, Apple said it removed references to 4G on its website, but some people are still complaining about what ASA calls “other potentially problematic claims about the iPad.” Apple reportedly still refers to 4G features, but adds the disclaimer that “4G LTE is supported only on AT&T and Verizon networks in the US, and on Bell, Rogers and Telus networks in Canada.”

Apple may not market “4G” iPad in the UK originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 14:30:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

When to get the best deals on Apple products

Image

Our buddies at Dealnews sent a link yesterday to a fascinating post written by blogger Louis Ramirez. Over the past three years, they’ve been collecting pricing data from Apple and other retailers, and now Dealnews has come up with some guidelines on how long to wait after the introduction of a new Apple product to get the best price on it.

The figures vary from device to device, but you can usually expect to see a fairly quick drop in price from Apple Authorized Resellers like MacConnection, MacMall, and Amazon. For an 11″ MacBook Air, for example, the price from these resellers dropped US$49 off of Apple’s suggested retail price in about a day, while you’d have to wait for almost two months to see a $40 discount on the price of an iPad.

As you’d expect, the bargains get larger as time elapses. Wait four months after the release of an 11″ MacBook Air and that $49 discount climbs to $149. How about the iPad? You need to wait until just before the release of a new model to see any significant discount — 12 months after the release of a model, you’ll commonly see reseller discounts of $139.

For those of you who can wait a bit while before picking up the latest Apple technology from an Authorized Reseller — not the local Apple Store — it looks like you can save some real money. Be sure to take a look at the Dealnews post for further details on all of the major Apple products.

When to get the best deals on Apple products originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 14:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Financial Times to discontinue iPad, iPhone apps, move to HTML5

The Financial Times has announced that it is killing its iPad and iPhone apps. That doesn’t mean that iOS users are going to be left out in the cold in terms of getting the latest financial news; it just means that the company is completing the move from an app-based edition to an HTML5 web app.

The FT pulled its iOS app from the iTunes Store last year, but subscribers who had it installed could still use the app to grab and view content. The Financial Times is now going to make the app unusable, forcing the few remaining users to move to the HTML5 edition.

It was reported that the user base for the web app actually overtook that of the iOS app within three months of being launched. The mobile site provides 12 percent of all new Financial Times subscriptions and contributes to 19 percent of all the FT.com web traffic.

Financial Times to discontinue iPad, iPhone apps, move to HTML5 originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 13:30:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Inkling releases Frommer’s travel guides for iPhone and iPad

Frommer’s and Inkling have teamed up to bring the popular series of travel guides to the iPad and the iPhone, says a report in Paid Content. The interactive titles will feature retina-optimized photographs, interactive tours, maps, notebooks, and real-time weather. Users will also be able to share notes and sync itineraries between devices.

The series will launch with seven titles covering Costa Rica, France, Alaska, California, Japan, Spain and Great Britain. Additional locations will roll out by the end of the year. The interactive apps are available from US$9.99 to $14.99, deepening on the geographic area covered by the guide.

Inkling releases Frommer’s travel guides for iPhone and iPad originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 13:00:00 EST. Please see our terms for use of feeds.

Source | Source | Permalink | Email this | Comments

Flashback was earning about $10K per day

People often wonder about what motivates the creators of malware. In the case of the Flashback malware that infected several hundred thousand Macs, it turns out that the motivator was money.

A post on the Symantec official blog listed the stages of infection from Flashback:

  1. A user visits a compromised website.
  2. The browser is redirected to an exploit site hosting numerous Java exploits.
  3. CVE-2012-0507 is used to decrypt and install the initial OSX.Flashback.K component.
  4. This component downloads a loader and an Ad-clicking component.

That ad-clicking component is what made the money for the scoundrels who wrote the malware. As the Symantec post explains, the malware specifically targets searches made on Google. Depending on the search query, the malware redirected the Mac user to another page chosen by the attacker, and the attacker received revenue from the click-through. Since Google never received the intended ad click, they lost revenue.

Symantec analyzed a similar botnet last year and determined that about 25,000 infected machines could net the attacker about US$450 per day. Based on the breadth of the Flashback attack, they estimated that the malware was earning its creators almost $10,000 per day.

If you haven’t updated your Mac to counteract a possible Java malware attack, or run Apple’s free tool for removing the malware from Macs that don’t have Java installed, be sure to run Software Update as soon as possible to protect yourself.

[via Macworld]

Flashback was earning about $10K per day originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 12:30:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Apple wants Samsung name obscured on video players in courtroom

Unsurprisingly, Apple is really sweating the details when it comes to its upcoming court date with Samsung.

FOSS Patents has noted that a court filing revealed Apple doesn’t want to see any Samsung logos or brand identification in the courtroom.

“Apple intends to bring a motion for ‘[o]bscuring the ‘Samsung’ logo on the court’s video display for jurors.’ Apparently the United States District Court for the Northern District of California uses Samsung equipment for this purpose.”

Apple doesn’t want that jury to think about Samsung’s technology contributions, so the request is a bit picky — but it makes sense. Apple also doesn’t want to see any references to Steve Jobs’s comments to biographer Walter Isaacson about waging “thermonuclear war” against Samsung.
Of course I’m sure Apple’s attorneys won’t be bothered if any of the attorneys are taking notes on their MacBooks or iPads.

Apple wants Samsung name obscured on video players in courtroom originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 12:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

RIM claims responsibility for "Wake Up" stunt at Apple Store

RIM, maker of the BlackBerry, has claimed responsibility for the ultra lame “Wake Up” flash mob stunt that appeared outside the Sydney Apple store last week. The stunt saw flash mobs pull out black signs that read “Wake Up.” When confronted with the signs, shoppers at the Apple Store seemed to have thought the same thing as everyone else, “Wake up to what?” then continued shopping and went about their day.

Until RIM owned up to the stunt, many had thought it was spearheaded by Samsung, which has performed similar stunts in the past. Tiphereth Gloria, a social media strategist at VML Australia, told The Age, “The punch line — which is the fact that BlackBerry is behind it — is what makes it fail because BlackBerry is not associated with any kind of success.”

The past couple of years have not been kind to the BlackBerry, as both the iPhone and the Android-based smartphone offerings have chewed away market share from the one-time market juggernaut. Aside from the shifts in the competitive landscape, at times RIM itself seemed to encourage its own demise. First, the Canadian phone maker suggested that the iPhone was a physical impossibility when Apple announced it in 2007, and subsequently the continued self-denial that the iPhone wasn’t a threat to RIM’s business didn’t help matters.

Unfortunately, RIM doesn’t seem to know (or at least admit) that it’s the next Palm. When your brand is weakening, you need killer products and not marketing stunts to get your game back. But hey, at least it’s starting to admit “BlackBerry isn’t for everyone.”

RIM claims responsibility for “Wake Up” stunt at Apple Store originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 11:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Alfred updated with new themes, drag-and-drop support

ImageAlfred for Mac (our review from last year) has been updated to version 1.2. Alfred is a utility that’s part app launcher, part navigation tool and part web service. This updated adds two new themes: Dark and Smooth & Pistachio (I prefer the original). There’s also support for large type which my aging eyes appreciate as well as an option to drag results out of Alfred an onto the desktop, into an email message and so on. That’s pretty handy.

There are also lots of improvements and you’ll find the full list here. Alfred for Mac is free but the optional Powerpack (£15) adds a lot of additional functionality.

Alfred updated with new themes, drag-and-drop support originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 10:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Korea loosens regulations on mobile phone sales

Korea is establishing a new policy that’ll let customers buy phones and service separately, according to a report in MK Business news. Wireless customers will be able to shop for phones from a variety of retailers including supermarkets, malls and manufacturers like Apple. Even phones bought overseas can be activated as long as the handset uses the same frequencies as the Korean carrier.

Once they buy their phones, customers can subscribe to a calling and data plan later. This is a significant change from current policy, which forces customers to get their phones directly from the carrier and sign up for service immediately.

Reaction to this change is mixed in the Korean country. Some experts hope this will loosen the grip that carriers have on the Korean mobile marketplace. Others think this may harm consumers who will have to pay more for service because carriers may stop offering discounts. The new policy is expected to go into effect today, May 1.

[Via Electronista]

Korea loosens regulations on mobile phone sales originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 01 May 2012 09:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments