Skip to content

Instantly share code, notes, and snippets.

@dazuiba
Created September 4, 2010 13:36
Show Gist options
  • Save dazuiba/565185 to your computer and use it in GitHub Desktop.
Save dazuiba/565185 to your computer and use it in GitHub Desktop.
objective-c学习笔记
#@interface中声明变量是否是必须的
@interface Car : NSObject {
float p1; //可以删除
float _p2;//可以删除
}
@property float p1;
@property float p2;
@end
@implementation Car
@synthesize p1;
@synthesize p2 = _p2;
@end
# 解析sina微薄的created_at时间格式
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEE MMM dd HH:mm:ss ZZ yyyy"];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSLog(@"newDateString %@", [formatter dateFromString:@"Thu Sep 23 00:13:17 +0800 2010"]);
#option + click keyword
=> jump to document
#option+command + click keyword
=> find text in document
== 如何实现pull down to request
@interface PullToRefreshTableViewController : UITableViewController {
EGORefreshTableHeaderView *refreshHeaderView;
}
@implementation PullToRefreshTableViewController
//用户开始下拉
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if (!reloading) {
checkForRefresh = YES; // only check offset when dragging
//更新视图中的"更新时间"
refreshHeaderView.lastUpdatedDate = refreshHeaderView.lastUpdatedDate;
}
}
//用户下拉中...
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (reloading) return;
if (checkForRefresh) {
if (refreshHeaderView.isFlipped && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && !reloading) {
// 提示文字: 请下拉更新
[refreshHeaderView flipImageAnimated:YES];
[refreshHeaderView setStatus:kPullToReloadStatus];
} else if (!refreshHeaderView.isFlipped && scrollView.contentOffset.y < -65.0f) {
// 提示文字: 请松开,发出下拉请求
[refreshHeaderView flipImageAnimated:YES];
[refreshHeaderView setStatus:kReleaseToReloadStatus];
}
}
}
//用户终止下拉
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (reloading) return;
// 如果下拉距离大于65像素(13%), 显示pulling view...
if (scrollView.contentOffset.y <= - 65.0f) {
if ([self.tableView.dataSource respondsToSelector:@selector(reloadTableViewDataSource)]) {
[self showReloadAnimationAnimated:YES];
[self reloadTableViewDataSource];
}
}
//不再检测下拉刷新
checkForRefresh = NO;
}
== how to use iphone preference
* create setting bundle, and add a item
<plist version="1.0">
<dict>
<key>Title</key>
<string>${PRODUCT_NAME}</string>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Authentication</string>
</dict>
<dict>
<key>Key</key>
<string>delay</string>
<key>DefaultValue</key>
<string>2</string>
<key>Title</key>
<string>Delay</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
* use in your code
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"..............................%@", [defaults valueForKey: @"delay"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment