ios 开发框架原始雏形 01
生活随笔
收集整理的這篇文章主要介紹了
ios 开发框架原始雏形 01
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self) {// Custom initialization
}return self;
}#pragma mark - Start 數(shù)據(jù)入口-(void)inputData
{//對程序級的全局變量用局部變量獲取出來,然后轉(zhuǎn)存給當(dāng)前viewController的全局變量//在當(dāng)前viewController中,只使用當(dāng)前類的全局變量,不要在程序中使用 整個程序的全局變量,那樣數(shù)據(jù)將會失控
}#pragma mark - step 1 畫面開始- (void)viewDidLoad
{[super viewDidLoad];[self inputData]; //獲取本類需要用到的基本數(shù)據(jù)
[self loadBasicView]; //加載最基本的界面//開啟子線程到網(wǎng)絡(luò)上獲取數(shù)據(jù)NSThread *thread1 = [[NSThread alloc]initWithTarget:self selector:@selector(thread1_getData) object:nil];[thread1 setName:@"第一個子線程,用于獲取網(wǎng)絡(luò)數(shù)據(jù)"];[thread1 start];
}#pragma mark - step 2 加載最基本的界面
-(void)loadBasicView
{}
#pragma mark - step 3 第一個子線程 : 用于獲取網(wǎng)絡(luò)數(shù)據(jù) 相當(dāng)于為TabelView生成數(shù)據(jù)源
-(void)thread1_getData
{//自定義獲取數(shù)據(jù)操作//////回到主線程,更新用戶界面 疑問: 用下面這種方式更新界面,會有延遲問題
// [self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:NO];[self updateUI]; //被迫先用這種方式
}
#pragma mark - step 4 更新用戶界面 (同時開啟第二個子線程,下載圖片)
-(void)updateUI
{//更新用戶界面操作,如 [tableView reload]; 等//////開啟單獨(dú)的第二個線程 下載主界面的頭圖片,并一個一個進(jìn)行顯示NSThread *thread2 = [[NSThread alloc]initWithTarget:self selector:@selector(thread2_downLoadImagesForView) object:nil];[thread2 setName:@"第二個子線程,用于下載圖片,并一個一個顯示在主界面"];[thread2 start];
}
/*
#pragma mark - TableViewDelegateMethods//組的個數(shù)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{return 1;
}//行數(shù)
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return 1;
}//各項(xiàng)的高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{return 70 ;
}//每個單元行中的內(nèi)容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{static NSString *cellIdetify = @"cell";UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdetify] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleGray; //設(shè)置分割線的顏色//對cell進(jìn)行自定義return cell;
}//單元格被選中
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{}*/#pragma mark - step 5 開啟第二個子線程:下載圖片,并添加到 self.view 上
-(void)thread2_downLoadImagesForView
{}#pragma mark - step 6 處理畫面中的按鈕的響應(yīng)事件#pragma mark - step7 畫面消失- (void)viewDidUnload
{[super viewDidUnload];// Release any retained subviews of the main view.// e.g. self.myOutlet = nil;
}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return (interfaceOrientation == UIInterfaceOrientationPortrait);
}#pragma mark - End 數(shù)據(jù)出口-(void)outputData
{//對類的全局變量進(jìn)行歸位(或許不必)//對類中輸出的數(shù)據(jù)進(jìn)行集中管理//用類的全局變量對應(yīng)用程序級全局變量進(jìn)行管理
}
?
總結(jié)
以上是生活随笔為你收集整理的ios 开发框架原始雏形 01的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TOUCH(1)
- 下一篇: 1001.Reverse Root