你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios 移動應用通用邏輯流程

ios 移動應用通用邏輯流程

編輯:IOS開發綜合

 

1 start

 

- (IBAction)clickStart:(id)sender {
    for (int i = 0; i < 6; i++) {
        UILabel *label = (UILabel *)[self.view viewWithTag:i + 10000];
        label.textColor = [UIColor blueColor];
    }
    
    [self performSelector:@selector(start) withObject:nil afterDelay:1];
}

2 發送請求

 

 

-(void) httpGET{
    UILabel *label = (UILabel *)[self.view viewWithTag:1 + 10000];
    label.textColor = [UIColor redColor];
    __block id myself =self;
    HttpRequest *request = [self.entityModel.requestHelper get:@api/nodes.json];
    [request succeed:^(HttpRequest *op) {
        UILabel *label = (UILabel *)[self.view viewWithTag:2 + 10000];
        label.textColor = [UIColor redColor];
        
        if([op isCachedResponse]) {
            NSLog(@Data from cache %@, [op responseString]);
            [myself parseData:[op responseString] isCachedResponse:YES];
        }
        else {
            NSLog(@Data from server %@, [op responseString]);
            [myself parseData:[op responseString] isCachedResponse:NO];
        }
    } failed:^(HttpRequest *op, NSError *err) {
        NSString *str = [NSString stringWithFormat:@Request error : %@, [err localizedDescription]];
        NSLogD(@%@, str);
        
        // SHOWMBProgressHUD(@Message, str, nil, NO, 3);
        [self loadFromDBProcess];
    }];
    
    [self.entityModel.requestHelper submit:request];
}

3 解析請求

 

 

-(void) parseData:(NSString *)str isCachedResponse:(BOOL)isCachedResponse{
    UILabel *label = (UILabel *)[self.view viewWithTag:3 + 10000];
    label.textColor = [UIColor redColor];
    
    self.model = [str toModels:[RubyChinaNodeEntity class]];
    
    [self performSelector:@selector(refreshUI) withObject:nil afterDelay:1];
    
    if (isCachedResponse) {
        ;
    }else{
        [self performSelector:@selector(saveToDBProcess) withObject:nil afterDelay:1];
    }
}

4 持久化

 

 

-(void) saveToDBProcess{
    UILabel *label = (UILabel *)[self.view viewWithTag:4 + 10000];
    label.textColor = [UIColor redColor];
    PERF_ENTER_( saveAllToDB )
    [self.model saveAllToDB];
    PERF_LEAVE_( saveAllToDB )
}

5 刷新UI

 

 

-(void) refreshUI{
    UILabel *label = (UILabel *)[self.view viewWithTag:5 + 10000];
    label.textColor = [UIColor redColor];
    
    if (self.model && self.model.count > 0) {
        NSString *str = [[self.model objectAtIndex:0] YYJSONString];
        SHOWMBProgressHUD(@Data, str, nil, NO, 3);
    }
}

6 讀取數據庫

 

 

-(void) loadFromDBProcess{
    self.model = [NSArray loadFromDBWithClass:[RubyChinaNodeEntity class]];
    
    [self performSelector:@selector(refreshUI) withObject:nil afterDelay:1];
}

 

 


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved