ios 开发框架原始雏形 01

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark - Start 数据入口

-(void)inputData
{
    //对程序级的全局变量用局部变量获取出来,然后转存给当前viewController的全局变量
    //在当前viewController中,只使用当前类的全局变量,不要在程序中使用 整个程序的全局变量,那样数据将会失控
    
}

#pragma mark - step 1 画面开始

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self inputData];      //获取本类需要用到的基本数据
    
    [self loadBasicView];  //加载最基本的界面
    
    //开启子线程到网络上获取数据
    NSThread  *thread1 = [[NSThread alloc]initWithTarget:self selector:@selector(thread1_getData) object:nil];
    [thread1 setName:@"第一个子线程,用于获取网络数据"];
    [thread1 start]; 
}

#pragma mark - step 2 加载最基本的界面
-(void)loadBasicView
{
    
}
#pragma mark - step 3 第一个子线程 : 用于获取网络数据  相当于为TabelView生成数据源 
-(void)thread1_getData
{
    //自定义获取数据操作
    //
    //
    
    
    //回到主线程,更新用户界面  疑问: 用下面这种方式更新界面,会有延迟问题
//    [self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:NO];
    [self updateUI];  //被迫先用这种方式
}
#pragma mark - step 4 更新用户界面  (同时开启第二个子线程,下载图片)
-(void)updateUI
{
    //更新用户界面操作,如 [tableView reload]; 等
    //
    //
    
    
    //开启单独的第二个线程 下载主界面的头图片,并一个一个进行显示
    NSThread *thread2 = [[NSThread alloc]initWithTarget:self selector:@selector(thread2_downLoadImagesForView) object:nil];
    [thread2 setName:@"第二个子线程,用于下载图片,并一个一个显示在主界面"];
    [thread2 start];
}
/*
#pragma mark - TableViewDelegateMethods

//组的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

//行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

//各项的高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70 ;
}

//每个单元行中的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdetify = @"cell";
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdetify] autorelease];  
    cell.selectionStyle = UITableViewCellSelectionStyleGray;  //设置分割线的颜色
    
    //对cell进行自定义
    
    return cell;
}


//单元格被选中
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}
 */

#pragma mark - step 5 开启第二个子线程:下载图片,并添加到 self.view 上
-(void)thread2_downLoadImagesForView
{
    
}

#pragma mark - step 6 处理画面中的按钮的响应事件


#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 数据出口

-(void)outputData
{
    //对类的全局变量进行归位(或许不必)
    //对类中输出的数据进行集中管理
    //用类的全局变量对应用程序级全局变量进行管理
    
    
}
原文地址:https://www.cnblogs.com/ygm900/p/3107745.html