新浪微博-整理筆記

10月26號整理javascript

1.得到項目中info.plist文件的內容
1> [NSBundle mainBundle].infoDictionary
2> 版本號在info.plist中的key:kCFBundleVersionKey

2.自定義控制器的view
重寫loadView方法(不須要調用[super loadView])

3.控制器view的高度和狀態欄的關係
建立控制器的view時,系統會檢測狀態欄是否顯示
* 若是有狀態欄,那麼控制器view的高度是460(iPhone5中是548)
* 若是沒有狀態欄,那麼控制器view的高度是480(iPhone5中是568)

4.[UIScreen mainScreen].applicationFrame的取值
以3.5inch爲例(320x4801> 沒有狀態欄,applicationFrame的值{{0, 0}, {320, 480}}
2> 有狀態欄,applicationFrame的值{{0, 20}, {320, 460}}

5.按鈕的狀態
UIControlStateNormal       普通(默認的狀態)
UIControlStateHighlighted  高亮(用戶長按的時候)
UIControlStateDisabled     失效(經過代碼控制:enabled屬性)
UIControlStateSelected     選中(經過代碼控制:selected屬性)

6.錯誤調試技巧
1> 一個控件沒法顯示出來的可能緣由
* 沒有寬高(寬高爲0)
* 位置不對
* hidden=YES
* 沒有被addSubview到屏幕上

2> 一個UIScrollView沒法滾動
* contentSize沒有值
* 不能接收到觸摸事件

3> 一個控件沒法跟用戶交互(沒法接收事件)的可能緣由
* (父控件的)userInteractionEnabled = NO;
* (父控件的)hidden = YES
* (父控件的)alpha <= 0.01
* (父控件的)背景是clearColor

7.按鈕的設置
// 高亮狀態下不更改圖片的顏色
self.adjustsImageWhenHighlighted = NO;
// 是否選中狀態
self.selected = YES;
// 是否可用狀態
self.enabled = YES;

10月27號整理java

1、按鈕的設置
0.設置背景圖片
[btn setBackgroundImage:image forState:UIControlStateNormal];

1.設置內部UIImageView的圖片
[btn setImage:image forState:UIControlStateNormal];
// 不能寫成btn.imageView.image = image;

2.設置內部UILabel的文字
[btn setTitle:@"43" forState:UIControlStateNormal];
// 不能寫成btn.titleLabel.text = @"43";

3.調整內部ImageView的frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect

4.調整內部UILabel的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect

5.覆蓋父類在highlighted時的全部操做
- (void)setHighlighted:(BOOL)highlighted { }

6.文字居中
self.titleLabel.textAlignment = NSTextAlignmentCenter;

7.文字大小
self.titleLabel.font = [UIFont systemFontOfSize:12];

8.圖片的內容模式
self.imageView.contentMode = UIViewContentModeCenter;

2、添加子控制器
- (void)addChildViewController:
* 會將子控制器添加到childViewControllers,而且子控制器是有順序的
* 目的就是持有子控制器,不讓子控制器銷燬,保證主控制器在,子控制器就在

3、讓一個控制器擁有導航欄的最快方法:包裝一層導航控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];

4、UIBarButtonItem
1> 建立一個帶有文字的item
[[UIBarButtonItem alloc] initWithTitle:@"設置" style:UIBarButtonItemStyleBordered target:nil action:nil]

2> 建立一個包裝了自定義View的item
- (id)initWithCustomView:(UIView *)customView

5、設置導航欄UINavigationBar主題
// 1.appearance方法返回一個導航欄的外觀對象
// 修改了這個外觀對象,至關於修改了整個項目中的外觀
UINavigationBar *bar = [UINavigationBar appearance];

// 2.設置導航欄的背景圖片
[bar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

// 3.設置導航欄文字的主題
[bar setTitleTextAttributes:@{
  UITextAttributeTextColor : [UIColor blackColor],
  UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
 }];

6、設置導航按鈕UIBarButtonItem主題
// 1.修改全部UIBarButtonItem的外觀
UIBarButtonItem *barItem = [UIBarButtonItem appearance];
// 2.修改item的背景圖片
[barItem setBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:image2 forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
// 3.修改item上面的文字樣式
NSDictionary *dict = @{
    UITextAttributeTextColor : [UIColor darkGrayColor],
    UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
};
[barItem setTitleTextAttributes:dict forState:UIControlStateNormal];
[barItem setTitleTextAttributes:dict forState:UIControlStateHighlighted];

7、設置狀態欄樣式
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;

10月29號整理json

1、Cell的設置
1.設置cell的背景view和選中時的背景view
UIImageView *bg = [[UIImageView alloc] init];
bg.image = [UIImage imageNamed:@"abc.png"];
cell.backgroundView = bg;

UIImageView *selectedBg = [[UIImageView alloc] init];
selectedBg.image = [UIImage imageNamed:@"cde.png"];
cell.selectedBackgroundView = selectedBg;

2.設置cell最右邊的指示器(好比箭頭\文本標籤)
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_arrow.png"]];

2、tableView的設置
1.設置table頭部和底部的view
// 底部(寬度固定是320)
tableView.tableFooterView = footer;
// 頭部(寬度固定是320)
tableView.tableHeaderView = header;

2.設置每一組頭部和底部的高度
tableView.sectionHeaderHeight = 5;
tableView.sectionFooterHeight = 0;

3.設置tableView的背景
// 當tableview的樣式爲group時,若是想更換背景,必須清除默認條紋狀的backgroundView
// backgroundView的優先級 > backgroundColor
tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor redColor];

10月30號整理api

1、AFN的使用
1.依賴的框架
* MobileCoreServices.framework
* SystemConfiguration.framework
* Security.framework

2.主頭文件:AFNetworking.h

3.建立POST請求對象
// BaseURL是基準路徑,格式爲-> 協議頭://主機名 ,不能包含其餘路徑
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"https://api.weibo.com"]];

// Method是請求方法
// path是拼接在基準路徑後面的請求路徑
// parameters是POST請求的參數
NSURLRequest *post = [client requestWithMethod:@"POST" path:@"oauth2/access_token" parameters:@{
                      @"client_id" : kAppKey,
                      @"client_secret" : kAppSecret,
                      @"grant_type" : @"authorization_code",
                      @"redirect_uri" : kRedirectURI,
                      @"code" : requestToken
}];

4.發送請求,解析服務器的JSON數據
// 建立操做對象
NSOperation *op = [AFJSONRequestOperation JSONRequestOperationWithRequest:post
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    // AFN認爲請求成功會調用
}
failure : ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
    // AFN認爲請求失敗會調用
}];

// 執行操做
[op start];

5.AFJSONRequestOperation默認不接收text/plain類型的數據,當服務器返回text/plain類型的數據時,會認爲出錯了。能夠經過修改源代碼解決問題
* 修改AFJSONRequestOperation的下列方法
+ (NSSet *)acceptableContentTypes {
    return [NSSet setWithObjects:@"text/plain", @"application/json", @"text/json", @"text/javascript", nil];
}

2、MBProgressHUD的使用
1.顯示HUD
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"哥正在加載中...";
hud.dimBackground = YES;

2.移除hud
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];

3、工具類的做用
1.封裝某一塊獨立的業務功能,好比存儲數據、發送網絡請求等
2.每一個工具類的做用
* HttpTool:負責發送整個微博項目的get\post請求
* StatusTool:負責管理微博數據:抓取微博數據、發送微博
* AccountTool:負責管理帳號(存儲\讀取帳號)

 10月1號瀏覽器

1、SDWebImage的使用
1.依賴的框架
* ImageIO.framework
* MapKit.framework

2.UIImageView下載圖片須要的頭文件:UIImageView+WebCache.h

3.調用方法下載圖片
// url是圖片路徑
// placeholder是佔位圖片(正在下載圖片時,暫時顯示的圖片)
// options是緩存策略
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options

4.緩存策略-SDWebImageOptions
默認是開啓了硬盤\內存緩存的
* SDWebImageRetryFailed   下載失敗了會再次嘗試下載
* SDWebImageLowPriority   當UIScrollView等正在滾動時,延遲下載圖片(放置scrollView滾動卡)
* SDWebImageCacheMemoryOnly 只緩存到內存中,不緩存到硬盤上
* SDWebImageProgressiveDownload 圖片會一點一點慢慢顯示出來(就像瀏覽器顯示網頁上的圖片同樣)
* SDWebImageRefreshCached 將硬盤緩存交給系統自帶的NSURLCache去處理,當同一個URL對應的圖片常常更改時能夠用這種策略

通常使用SDWebImageRetryFailed | SDWebImageLowPriority

2、動態改變Cell的高度
1.利用tableView代理方法的返回值決定每一行cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

3、UIFont
// 返回字體的行高
* [UIFont systemFontOfSize:10].lineHeight

10月2號緩存

1、每一個Cell高度不一致的通常作法:
1.自定義一個cell,在initWithStyle:reuseIdentifier:構造方法中添加全部可能顯示的子控件

2.新建一個模型類,好比StatusCellFrame,做用是:描述一個Cell內部全部子控件的frame屬性
* 提供一系列CGRect類型的屬性給Cell訪問
* 提供一個接口來接收模型數據(好比Status)
* 在接收模型數據的同時,計算全部子控件的frame和cell的高度

3.回到控制器(代理和數據源)
1> 在tableView:heightForRowAtIndexPath:方法中利用StatusCellFrame返回cell的高度
2> 在tableView:cellForRowAtIndexPath:方法中
* 新建自定義cell
* 給Cell傳遞對應的StatusCellFrame對象

4. 自定義Cell
1> 提供接口接收StatusCellFrame對象
2> 在接收StatusCellFrame對象的同時,設置全部子控件的frame,設置全部子控件的數據

2、日期處理
1.將字符串轉成NSDate
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSDate *date = [fmt dateFromString:@"2013-08-08 17:45:34"];

2.將NSDate轉爲字符串
NSString *timeStr = [fmt stringFromDate:date];

 10月4號服務器

1、自動伸縮屬性
UIViewAutoresizingNone                 不伸縮
UIViewAutoresizingFlexibleLeftMargin   跟父控件左邊的距離自動伸縮
UIViewAutoresizingFlexibleRightMargin  跟父控件右邊的距離自動伸縮
UIViewAutoresizingFlexibleTopMargin    跟父控件頂部的距離自動伸縮
UIViewAutoresizingFlexibleBottomMargin 跟父控件底部的距離自動伸縮
UIViewAutoresizingFlexibleWidth        寬度跟隨父控件寬度自動伸縮
UIViewAutoresizingFlexibleHeight       高度跟隨父控件高度自動伸縮

2、設置按鈕(UIButton)文字和圖片的間距
@property(nonatomic) UIEdgeInsets titleEdgeInsets;
@property(nonatomic) UIEdgeInsets imageEdgeInsets;

3、新浪數據分頁傳遞的參數
* since_id : 會加載 微博ID > since_id 的數據(也就是時間比較晚、比較新的數據)
* max_id : 會加載 微博ID <= max_id 的數據(也就是時間比較早、比較舊的數據)

4、MJRefresh的使用
0.先加入主頭文件
#import "MJRefresh.h"

1.添加下拉刷新
MJRefreshHeaderView *header = [MJRefreshHeaderView header];
header.scrollView = self.tableView;
header.delegate = self;

2.添加上拉加載更多
MJRefreshFooterView *footer = [MJRefreshFooterView footer];
footer.scrollView = self.tableView;
footer.delegate = self;

3.監聽刷新狀態,有2種方式
1> 設置代理delegate,一旦控件進入了刷新狀態,就會調用delegate的下列方法
- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
    if ([refreshView isKindOfClass:[MJRefreshFooterView class]]) {
        // 上拉加載更多
        
    } else {
        // 下拉刷新
        
    }
}

2> 設置block回調
header.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
    
};
footer.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
    
};

4.經過代碼進入刷新狀態
[header beginRefreshing]; // 進入刷新狀態就會觸發相應的代理方法或者block
[footer beginRefreshing]; // 進入刷新狀態就會觸發相應的代理方法或者block

5.結束刷新狀態,回到普通狀態
[header endRefreshing];
[footer endRefreshing];

6.能夠在MJRefreshBaseView.h中經過控制NeedAudio宏來開啓音頻功能

7.在MJRefreshFooterView.m和MJRefreshHeaderView.m中能夠修改控件顯示的文字

5、若是想在內部限制某個控件的寬高,不讓外界隨便改,能夠重寫setFrame:方法,在此方法內部設置本身的寬高

10月5號網絡

1、導航控制器的代理
1.UINavigationController的delegate屬性

2.代理方法
1> 即將顯示新控制器時調用
/*
 navigationController : 導航控制器
 viewController : 即將顯示的新控制器
 */
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

2> 新控制器顯示完畢時調用
/*
 navigationController : 導航控制器
 viewController : 顯示完畢的新控制器
 */
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated

2、隱藏控制器剛出現時的滾動條
重寫控制器的viewDidAppear方法,覆蓋父類默認的操做:顯示滾動條

3、tableView每組的頭部控件
1.控件寬度默認就是tableView的寬度
2.控件高度由下面的代理方法決定
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

4、經過tableView的代理方法控制某一行的cell可否達到高亮選中狀態
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
相關文章
相關標籤/搜索