Mail list: http://groups.google.com/group/iphone-dev
- A typical iPhone application has only one window, an application changes its content by changing the content views displayed in that window.
- Safari's Bookmarks
The Safari's bookmarks is located at ~/Library/Safari/Bookmarks.plist, the format of that file is "Apple Property List". The property list can be in binary format, and text format, you can use tool 'plutil' to convert the file between binary and text formts.
The date in Bookmarks.plist: - Get date string
- Convert string to NSTimeInterval (float)\
- Then call [NSDate dateWithTimeIntervalSinceReferenceDate:timeInterval] to convert date to NSDate
- Add Tool Bar Programmtically
- Create instance of UITooBar, suppoes it is toolBar, then sent tool bar style, size
- Create instances UIBarButtonItem, suppose they are item1, item2, item3;
- Create array like:
NSArray itemsArray = [NSArray arrayWithObjects:item1, item2, item3, nil]; - Add items to tool bar
[toolBar setItems:itemsArray animated:YES]; - Add tool bar to current view
[[self view] addSubView:toolBar];
- How to Create View Controller Being Contained in Nib File
Sometimes, you add view controller into your Nib file, but how to create this type ofcontroller: - Customize View Controller
@interface MyViewController : UIViewController
{
IBOutlet UIViewController *controller;
}
@property (nonatomic,retain) IBOutlet UIViewController *controller;
@end
@implementation MyViewController
@syntherize controller
@end - Create Connections
Create following connections: - View controller object embedded in Interface Builder to outlet
"controller" of class MyViewController; - View object embedded in Interface Builder to outlet "view" of class MyViewController.
- Create Instance of View Controller
MyViewController *aViewController = [[MyViewController alloc]
initWithNibName:@"MyNibFile" bundle:[NSBundle mainBundle]];
[window addSubView:aViewController.view]; - ...
- Add "x" At The Right of UITextField
textField.clearButtonMode = UITextFieldViewModeWhileEditing; - You can add view and/or view controller in Nib, then load the Nib file into application, or you can customize them by implementing sub-class of UIView/UIViewController.
- When you create a iPhone project via XCode, it generates some files, about the porpuse of those files, please refer to tutorial "Beginning iPhone Developer: Exploring the iPhone SDK" ch3 "Handling Basic Interaction".
- About UIScrollView
- Issue: Views added into UIScrollView is not shown
Solution: These views has been added to other views, but any view can't be sub-view of more than one views; so before adding those view to UIScrollView, please remove them from their previous views by calling removeFroSuperview. - Issue: ScrollView can't be scrolled
Solution: set contentSize of UISCrollView - Don't call UIScrollView.scrollRectToVisible in it's delegate, otherwise, application will dead-lock during scrolling.
- ...
- Replace internal interface of class
Class klass = objc_getClass("UIWebDocumentView");
if( klass == nil )
return; // if there is no UIWebDocumentView in the future.
// replace touch began event
method_exchangeImplementations(class_getInstanceMethod(klass,@selector(touchesBegan:withEvent:)),class_getInstanceMethod(klass, @selector(__replacedTouchesBegan:withEvent:)) ); - Sample: UICWebView
- UITableView
- If you want to add multiple controls into one table cell, you must define subclass of UITableViewCell, and add the controls as subview of customized UITableViewCell
- If you want to devide table view into multple section, and each section are grouped, you must set UITableView's Stype to 'Grouped', and implement UITableViewDelegate's function 'numberOfSections'
- If you want to set icon bedise table cell, you must implement UITableViewDelegate's function - (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
i.e: please refer to sample application UICatalog - ....
- Extrace resources from application (X86)
- Run-time error "EXC_BAD_ACCESS"
Invalid memory accessing, such as to access released memory (Refer to object after invoked release mothod) - Safe browser sample
SafeEyes, Smart Surfin
- Enumator/Simulator path under Mac OS X
~/Library/Application Support/iPhoneSimulator/User/
- How to get event when application terminate in UIView sub-class
1, Define a callback
- (void) applicationWillTerminate:(NSNotifiation *)notification
2, Register observer
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self seletor:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];
- How to customize control
Illustrate use UIViewController
- Create a new class CustomViewControl derived from UIViewController
- Add view controller in Nib
- When
view controller in Nib get focus, press Command-4 to bring up identity
inspector, then change the class of table view controller to
CustomViewControl
- Now, when you init frame with that nib file, the instance of CustomViewControl will be created.
- String format
%@ String ie. [[NSString alloc] initwithFormat:@"The name is %@", @"Jimmy"];
- Play system audio
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileUrlWithPath :xxxx], &soundID);
AudioServicesPlaySystemSound(soundID);
Before building, press menu Project > Add to Project... to add AudioToolBox.FrameWork under /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulatore2.1.sdk/System/Library/Frameworks/ to your project.
- Outlets and Actions
- Defien outlets in .h file
IBOutlet UIButton *myButton;
The IBOutlet keyword is defined like this:
#ifndef IBOutlet
#define IBOutlet
#endif
IBOutlet doesn absolutely nothins, it sole purpose is to act as a hint to tell Interface Builder that this is an interface variable that we are connect to an object in a nib file must be proceded by the IBOutlet keyword.
- Define action method
- (IBAction) doSomethins:(id)sender;
- Communicating Asynchronously
//Register notification observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getData:) name:NSFileHandleReadCompletionNotification
object:portHandle];
//Send message to read data asynchronously
[portHandle readInBackgroundAndNotify]; //portHande is a *NSFileHandle;
- ...
阅读(3672) | 评论(0) | 转发(0) |