IOS单例模式
来源:互联网 发布:评价算法性能的标准 编辑:程序博客网 时间:2024/06/05 12:42
#import "ShareInstanceViewController.h"
#import "HeadFile.h"
@interface ShareInstanceViewController ()
@end
@implementation ShareInstanceViewController
static ShareInstanceViewController *sharedObj = nil;
+ (ShareInstanceViewController *) sharedInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedObj=[[ShareInstanceViewController alloc] init];
});
return sharedObj;
}
+ (id) allocWithZone:(NSZone *)zone //第三步:重写allocWithZone方法
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedObj=[super allocWithZone:zone];
});
return sharedObj;
}
- (id) copyWithZone:(NSZone *)zone //第四步
{
return self;
}
- (id) retain
{
return self;
}
- (unsigned) retainCount
{
return UINT_MAX;
}
- (oneway void) release
{
}
- (id) autorelease
{
return self;
}
- (id)init
{
@synchronized(self) {
[super init];//往往放一些要初始化的变量.
return self;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 416+(isIPhone5?88:0)) style:UITableViewStyleGrouped];
table.backgroundView =nil;
// table.backgroundColor = [UIColor clearColor];
// table.backgroundColor=TABLE_BACKGROUDN_COLOR;
table.delegate=self;
table.dataSource=self;
table.showsVerticalScrollIndicator=NO;
table.separatorColor=TABLE_SEPARATOR_COLOR;
table.separatorInset = UIEdgeInsetsMake(0, 60, 0, 0);
[self.view addSubview:table];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]autorelease];
}
// cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];
// cell.selectedBackgroundView.backgroundColor = CELL_BACKGROUDN_COLOR;
UILabel *label=[[UILabel alloc] init];
label.frame=CGRectMake(54, 0, 200, 44);
label.backgroundColor=[UIColor clearColor];
label.text=[NSString stringWithFormat:@"----%d",indexPath.row];
[cell addSubview:label];
[label release];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
#import "HeadFile.h"
@interface ShareInstanceViewController ()
@end
@implementation ShareInstanceViewController
static ShareInstanceViewController *sharedObj = nil;
+ (ShareInstanceViewController *) sharedInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedObj=[[ShareInstanceViewController alloc] init];
});
return sharedObj;
}
+ (id) allocWithZone:(NSZone *)zone //第三步:重写allocWithZone方法
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedObj=[super allocWithZone:zone];
});
return sharedObj;
}
- (id) copyWithZone:(NSZone *)zone //第四步
{
return self;
}
- (id) retain
{
return self;
}
- (unsigned) retainCount
{
return UINT_MAX;
}
- (oneway void) release
{
}
- (id) autorelease
{
return self;
}
- (id)init
{
@synchronized(self) {
[super init];//往往放一些要初始化的变量.
return self;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 416+(isIPhone5?88:0)) style:UITableViewStyleGrouped];
table.backgroundView =nil;
// table.backgroundColor = [UIColor clearColor];
// table.backgroundColor=TABLE_BACKGROUDN_COLOR;
table.delegate=self;
table.dataSource=self;
table.showsVerticalScrollIndicator=NO;
table.separatorColor=TABLE_SEPARATOR_COLOR;
table.separatorInset = UIEdgeInsetsMake(0, 60, 0, 0);
[self.view addSubview:table];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]autorelease];
}
// cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];
// cell.selectedBackgroundView.backgroundColor = CELL_BACKGROUDN_COLOR;
UILabel *label=[[UILabel alloc] init];
label.frame=CGRectMake(54, 0, 200, 44);
label.backgroundColor=[UIColor clearColor];
label.text=[NSString stringWithFormat:@"----%d",indexPath.row];
[cell addSubview:label];
[label release];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
0 0
- iOS单例模式
- iOS 单例模式
- IOS 单例模式
- iOS 单例模式
- IOS单例模式
- ios单例模式
- iOS 单例模式
- iOS 单例模式
- IOS单例模式
- iOS 单例模式
- iOS 单例模式
- IOS 单例模式
- IOS---单例模式
- iOS--单例模式
- iOS 单例模式
- ios 单例模式
- iOS 单例模式
- IOS单例模式
- 经典面试题(二)附答案 算法+数据结构+代码 微软Microsoft、谷歌Google、百度、腾讯
- ZOJ 3713 In 7-bit(数学啊 )
- leetcode #102Binary Tree Level Order Traversal
- 给虚拟机磁盘扩容
- 获取客户端网卡MAC地址和IP地址的方法
- IOS单例模式
- C++调用Java WebService生成客户端文件
- bzoj 3196/tyvj p1730 二逼平衡树 树套树
- “浅拷贝”与“深拷贝”
- 严重: Null component Catalina:type=JspMonitor,name=jsp,WebModule=//localhost/dangdang,J2EEApplication=
- 优酷视频接口
- 蓝牙打印机DEMO程序
- RFID系统二进制树型搜索算法是如何解决碰撞的?简述其实现步骤
- 黑马程序员-IO流学习笔记-2