3 posts tagged “objective-c”
After a few months of .NET reporting/SSIS development work, I'm back to an iPhone project this week. One enhancement I added yesterday was a better formatted table section title in a UITableView. Before, the section title is either a bunch of unformatted (also incorrectly by locale) dates (e.g. 2009-09-30), or times (e.g. 14:58) straight from the data source. The enhancement/bug fix is to format the date or time to be locale aware so the title would either be "Wed Sep, 30 2009" or "2:58 PM" if you are in the US.
I started learning Objective-C when Apple released the iPhone SDK over a year ago, and started programming in it seriously at the beginning of this year. While there are many things I like about Objective-C as a OO language, there is one thing that continuously bother me.
- Implement the method without declaring it in the header file. This is (almost) equivalent to private method in C#/Java.
- Declare the method signature in the header file, and implement the method in the .m file. This is like declaring a method public in C#/Java.
Let's say you want to use UIActionSheet to show three buttons to the user with a cancel buttons in a UIView, which itself is managed by a UITabBarController:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Option 1", @"Option 2", @"Option 3", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
[actionSheet release];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Option 1", @"Option 2", @"Option 3", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
ApplicationDelegate *appDelegate = (ApplicationDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tabBarController = appDelegate.tabBarController_;
[actionSheet showInView:tabBarController.view];
[actionSheet release];