zoukankan      html  css  js  c++  java
  • dsfsdffsd

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    
    
    @end
    
    #import "AppDelegate.h"
    #import "ViewController.h"
    
    @interface AppDelegate ()
    
    @property (nonatomic,strong) ViewController *viewController;
    @end
    
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.rootViewController = self.viewController;
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    @end
    
    
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
    
    
    @end
    
    #import "ViewController.h"
    
    @interface ViewController ()
    @property (nonatomic,strong) NSMutableArray *randomNumbers;
    @property (nonatomic,strong) UITableView *myTableView;
    @end
    
    @implementation ViewController
    
    -(NSString *) fileLocation{
        NSArray *folders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        if ([folders count] == 0) {
            return nil;
        }
        NSString *documentsFolder = [folders objectAtIndex:0];
        return [documentsFolder stringByAppendingPathComponent:@"list.txt"];
    }
    
    - (BOOL)hasFileAlreadyBeenCreated{
        BOOL result = NO;
        NSFileManager *fileManager = [[NSFileManager alloc] init];
        if ([fileManager fileExistsAtPath:[self fileLocation]]) {
            result = YES;
        }
        return result;
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_async(concurrentQueue, ^{
            NSUInteger numberOfValuesRequired = 10000;
            if ([self hasFileAlreadyBeenCreated] == NO) {
                dispatch_sync(concurrentQueue, ^{
                    NSMutableArray *arrayOfRandomNumbers = [[NSMutableArray alloc] initWithCapacity:numberOfValuesRequired];
                    NSUInteger counter = 0;
                    for (counter = 0; counter < numberOfValuesRequired; counter++) {
                        unsigned int randomNumber = arc4random() %((unsigned int)RAND_MAX + 1);
                        [arrayOfRandomNumbers addObject:[NSNumber numberWithUnsignedInt:randomNumber]];
                    }
                    [arrayOfRandomNumbers writeToFile:[self fileLocation] atomically:YES];
                });
            }
            
            dispatch_sync(concurrentQueue, ^{
                if ([self hasFileAlreadyBeenCreated]) {
                    self.randomNumbers = [[NSMutableArray alloc] initWithContentsOfFile:[self fileLocation]];
                    [self.randomNumbers sortUsingComparator:^NSComparisonResult(id obj1,id obj2){
                        NSNumber *number1 = (NSNumber *)obj1;
                        NSNumber *number2 = (NSNumber *)obj2;
                        return [number1 compare:number2];
                    }];
                }
            });
            
            dispatch_sync(dispatch_get_main_queue(), ^{
                if ([self.randomNumbers count] > 0) {
                    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
                    self.myTableView.delegate = self;
                    self.myTableView.dataSource = self;
                    self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                    [self.view addSubview:self.myTableView];
                }
            });
        });
    }
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return self.randomNumbers.count;
    }
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        UITableViewCell *result = nil;
        static NSString *TableViewCellIdentifer = @"MyCells";
        result = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdentifer];
        if (result == nil) {
            result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableViewCellIdentifer];
            result.textLabel.text = [NSString stringWithFormat:@"%d",self.randomNumbers[indexPath.row]];
        }
        return result;
    }
    
    @end
  • 相关阅读:
    led呼吸灯
    定时器中断
    npgsql
    中断
    PAT (Advanced Level) 1128~1131:1128N皇后 1129 模拟推荐系统(set<Node>优化) 1130 中缀表达式
    PAT (Advanced Level) 1132~1135:1132 模拟 1133模拟(易超时!) 1134图 1135红黑树
    PAT (Advanced Level) 1136~1139:1136模拟 1137模拟 1138 前序中序求后序 1139模拟
    PAT (Advanced Level) 1140~1143:1140模拟 1141模拟 1142暴力 1143 BST+LCA
    PAT (Advanced Level) 1144~1147:1145Hash二次探查 1146拓扑排序 1147堆
    python实现http接口测试
  • 原文地址:https://www.cnblogs.com/elitiwin/p/4688635.html
Copyright © 2011-2022 走看看