iphone 开发小技巧备忘
1. 在uiviewcontroller声明nsstring property的方法:
NSString *groupName;
@property (nonatomic, assign) NSString *groupName;
2.Setting the back button title of a UINavigationItem
The following code will set the back button title of the current UINavigationItem:
The target: and action: parameters are definitely ignored (replaced by the default back button behavior) and the style also seems to be ignored because the back button retains its pointed left side.
This next block of code looks like it should do the same thing but does not work:
self.navigationItem.backBarButtonItem.title = [NSString stringWithString:@"Back"];
注意:一定要在当前页面设置backbarbuttonitem!!
MAJOR CAVEAT: As pointed out in this thread, "the back button is 'owned' by the previous view on the stack." In other words, the setBackBarButtonItem method should be called on the view that the user is navigating away from, rather than the view above which this button is actually displayed.
3. 调整tableviewcell 背景色- (void)viewDidLoad{ // Add a toolbar to the view CGRect toolbarFrame = CGRectMake(0, 372, 320, 44); UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame]; UIBarButtonItem *compassButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"compass.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(zoomToCurrentLocation)]; compassButton.width = 30.0f; // make the button a square shape [myToolbar setItems:[NSArray arrayWithObject:compassButton] animated:NO]; [compassButton release]; [self.view addSubview:myToolbar]; [super viewDidLoad];}
11. How to compare if two objects are really the same object?
The == operator tests whether the two expressions are the same pointer to the same object. Cocoa calls this relation “identical” (see, for example, NSArray's indexOfObjectIdenticalTo:).
To test whether two objects are equal, you would send one of them an isEqual: message (or a more specific message, such as isEqualToString:, if it responds to one), passing the other object. This would return YES if you really only have one object (equal to itself, obviously) or if you have two objects that are equal. In the latter case, == will evaluate to NO.
12. IOS支持的所有字体 font
http://iosfonts.com/
13. Advanced App Tricks
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html
14. 输入密码界面:
https://github.com/Koolistov/Passcode
http://code.google.com/p/kpasscode/
15. 程序和iTunes间共享文件
http://www.alterplay.com/ios-dev-tips/2010/11/file-sharing-from-app-to-itunes-is-too-easy.html
16. http://stackoverflow.com/questions/7989968/iphone-loading-view-slide-effect