// 单例模式实现要点: // 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