// 單例模式實現要點: // 1. 廢掉構造方法(調用的時候拋出異常) // 2. 提供一個類方法向外界返回該類的惟一實例 -(instancetype)init { @throw [NSException exceptionWithName:@"CDSingleton" reason:@"不容許調用構造方法" userInfo:nil]; // return nil; } // 此方法因爲沒有在.h文件中暴露接口至關因而私有方法 -(instancetype) initPrivate { if(self = [super init]) { _value = arc4random(); } return self; } +(instancetype) sharedInstance { // static類型的變量擁有全局的生命週期 static CDSingleton *instance = nil; // 使用同步塊保證在多線程環境下仍然是單例 //同步加鎖,在多線程中使用,可使線程安全 @synchronized(self) { if(!instance) { instance = [[self alloc] initPrivate]; } } return instance; }
+(instancetype)sharedInstance{ static HCDSingleton *singleton = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ singleton = [[HCDSingleton alloc]init]; }); return singleton; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"healthNewsTableViewCell"; healthNewsTableViewCell *cell = [myTableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; if (!cell) { cell = (healthNewsTableViewCell*)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: @"healthNewsTableViewCell"]; } return cell; } //再將數據綁定寫在WillDisPlayCell中 //讓UITableView稍微順滑點的方法 在顯示cell前被調用 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ healthNewsTableViewCell *MyCell = (healthNewsTableViewCell *)cell; MyCell.model = dataArray[indexPath.row]; MyCell.backgroundColor = [UIColor colorWithRed:0.936 green:0.941 blue:0.936 alpha:1.000]; }
1.-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; //這個方法返回每一個分段的行數,不一樣的分段返回不一樣的行數能夠用switch來作,若是是單個列表就直接返回單個你想要的函數便可。
2.-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; //這個方法返回咱們調用的每個單元格。經過咱們索引的路徑的section和row來肯定。
1.-(void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait; 該方法通常用於線程間相互通訊,即在一個線程中發送消息給另外一個線程。
2.-(void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait; 注:每個線程都有本身的Runloop,但非主線程的Runloop默認是關閉的,當須要進行非主線程的通訊時,須要確保通訊線程的Runloop是開啓的,不然發送給通訊線程的消息就不會被執行。
dispatch_get_main_queue();
2.全局並行隊列:在該隊列上提交的每一個任務,都會生成一個線程,並行的執行(不會等到另外一個執行完才執行) dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0);
3.串行隊列:在該隊列上提交的任務,生成一個線程,在該線程上順序執行,一個執行完後一個才能執行 dispatch_queue_create(「」,DISPATCH_QUEUE_SERIAL);
getPath:parameters:failure
,對AFHTTPRequestOperation進行同步處理。NSHomeDirectory
獲取。NSSearchPathForDirectotiesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)
//生成訂單信息及簽名請求參數沒有return_URL這個參數,商戶能夠根據自身狀況選擇簽名方法 //點擊獲取product實例,並初始化訂單信息 //訂單ID //商品標題 //商品描述 //商品價格 //回調URL