UIButton events
[someuibutton addTarget:self action:@selector(someEventHandlerFunction:)
forControlEvents:UIControlEventTouchUpInside];
- (void) someEventHandlerFunction:(id) button
{
}
Casting in Objective C
[(UIScrollView*)self.view scrollRectToVisible:textFieldRect animated:NO];
Check if class exists in the SDK
Class clss = NSClassFromString(@"SomeClassName") id classInstance = [[clss alloc] init];
Create Local Notification
UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"This is the alert message.";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.userInfo = [NSDictionary dictionaryWithObject:someText
forKey:kNotificationKey];
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
Detect notification in the foreground and background state
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive)
{
// Application was in the background
}
}
Code for multiple versions of iOS
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 30200 // code for less than iOS 3.2 #else // code for later than iOS 3.2 #endif
Defining outlets
@interface MyClass : NSObject
{
id aGenericOutlet;
NSView* aViewOutlet;
NSArray* multipleLabels;
NSArray* multipleObjects;
}
@property (nonatomic, retain) IBOutlet id aGenericOutlet;
@property (nonatomic, retain) IBOutlet NSView* aViewOutlet;
@property (nonatomic, retain) IBOutletCollection (UILabel) NSArray *mutipleLabels;
@property (nonatomic, retain) IBOutletCollection (id) NSArray *mutipleObjects;
- (IBAction)respondToButtonClick;
- (IBAction)respondToButtonClick:(id)sender;
- (IBAction)respondToButtonClick:(id)sender forEvent:(UIEvent*)event;
@end