V2EX
   Tag:
 UIActionSheet
Posted in iPhone on September 19th, 2008 by Xin

There are two ways to construct UI for iPhone apps, Interface Builder or programmatically. As of writing, both ways are still lacking features from each other.

One example is UIActionSheet, currently you can only add it to a view programmatically.

Another example is UIImageView, Interface Builder provides you various options to set the fill mode of image in UIImageView (e.g. Aspect Fill), while you can only have stretch mode in public API. Please correct me if you think this is not true, I’ll be grateful to know I’m wrong.

So, whether to use Interface Builder is up to your app. If your app is a simple data client has only several UITableView, and you’re comfortable with Interface Builder, then it may be your best choice.

But, sometimes to get all work done exclusively in Xcode IDE means productivity, since you can create a complete app without touching Interface Builder, and organize its hierarchy with your experience. It’s like writing web apps without visual tools like Expression Web. This may be a more productive way for complicated apps like games or SNS client, these apps are usually constructed by many layers of UIViewController and UIView.

Posted in iPhone on September 18th, 2008 by Xin

UIActionSheet is a very useful component missing from Interface Builder (as of writing, UIActionSheet is still missing from Interface Builder 3.1.1 of iPhone SDK 2.1), which means you can only add it programmatically.

You can create an instance of UIActionSheet like this:

UIActionSheet anActionSheet = [[UIActionSheet alloc] initWithTitle:@"Start a New Game" delegate:aDelegate cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Play Black", @"Play White", nil];

Its style can be configured:

anActionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;

From several choices:

  • UIActionSheetStyleAutomatic
  • UIActionSheetStyleDefault
  • UIActionSheetStyleBlackTranslucent
  • UIActionSheetStyleBlackOpaque

The delegate must adopt UIActionSheetDelegate protocol and implement this method to handle taps in UIActionSheet:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

And finally, you can make it show in a view by invoking showInView:

[anActionSheet showInView:aView]

UIActionSheet is used in many application, it’s great for prompting a list of options and let user choose one from the list. One example is Mail, when you tap reply, an UIActionSheet floats and let you choose from Reply / Reply All / Forward / Cancel.