首先推迟segue,延迟2-3秒,然后下一个推送segues很快

时间:2015-03-20 07:26:06

标签: ios objective-c uinavigationcontroller

在我的xcode项目中,我有四个屏幕并在它们之间推送segue。当我从主屏幕到第二屏幕时,我发现了一个包,我面临延迟2-3秒。之后,快速移动所有另一个屏幕。

我认为问题可能在于创作

    self.navigationController.viewControllers array

当我第一次强制推出segue这个数组时有一些延迟,当我进入屏幕之间时,我会自动切换到这个数组中的对象。

所以,我的问题:当我的主屏幕加载和工作没有先推送segue延迟时,我怎么能强制创建这个viewcontrollers数组?

我的主视图控制器代码:

  #import "ViewController.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet UILabel *bestScore;
@property (strong, nonatomic) IBOutlet UILabel *bibleVerseLabel;
@property (strong, nonatomic) IBOutlet UILabel *questionLabel;
@property (strong, nonatomic) IBOutlet UILabel *scoreLabel;
@property (strong, nonatomic) IBOutlet UIButton *startButton;

@end

@implementation ViewController

- (void)viewDidLoad {

    [NSThread sleepForTimeInterval:1];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)initButtonAndLabelViews{
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.png"]];
    _bibleVerseLabel.font = [UIFont fontWithName:@"BebasNeueBold" size:24];
    _questionLabel.font = [UIFont fontWithName:@"BebasNeueBook" size:34];
    _scoreLabel.font = [UIFont fontWithName:@"Bad Script" size:21];
    _bestScore.font = [UIFont fontWithName:@"Bad Script" size:21];
    _startButton.layer.cornerRadius = 5;
    _startButton.layer.borderWidth = 0.2;
    _startButton.clipsToBounds = YES;
    _startButton.titleLabel.font = [UIFont fontWithName:@"BebasNeueBold" size:34];
    _startButton.contentEdgeInsets = UIEdgeInsetsMake(6, 0, 0, 0);

}

-(void)viewWillAppear:(BOOL)animated{
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
    self.navigationItem.backBarButtonItem = backButton;
    [self initButtonAndLabelViews];
    [self.navigationController.navigationBar setTranslucent:YES];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.view.backgroundColor = [UIColor clearColor];
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];

    _bestScore.text = [NSString stringWithFormat:@"%ld", (long)[[NSUserDefaults standardUserDefaults] integerForKey:@"BestScore"]];
    [self randomBibleVerse];
}

- (void)randomBibleVerse{
    NSInteger randomVerseNumber = arc4random()%6;
    switch (randomVerseNumber) {
        case 0:
            _bibleVerseLabel.text = @"«Слово Твое — светильник ноге моей и свет стезе моей»\n\n(Псалом 118:105)";
            break;
        case 1:
            _bibleVerseLabel.text = @"«Ибо Ты возвеличил слово Твое превыше всякого имени Твоего»\n\n(Псалом 137:2)";
            break;
        case 2:
            _bibleVerseLabel.text = @"«Написано:не хлебом одним будет жить человек, но всяким словом, исходящим из уст Божиих»\n\n(Матфея 4:4)";
            break;
        case 3:
            _bibleVerseLabel.text = @"«Hо слово Господне пребывает вовек; а это есть то слово, которое вам проповедано»\n\n(1-ое Петра 1:25)";
            break;
        case 4:
            _bibleVerseLabel.text = @"«Слова Господни – слова чистые, серебро, очищенное от земли в горниле, семь раз переплавленное»\n\n(Псалом 11:7)";
             break;
        case 5:
            _bibleVerseLabel.text = @"«Радуюсь Я слову Твоему, как получивший великую прибыль»\n\n(Псалом 118:162)";
            break;
        case 6:
            _bibleVerseLabel.text = @"«Закон Твой – утешение мое»\n\n(Псалом 118:77)";
            break;
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

第二个视图控制器,我在第一时间延迟。

#import "CategoriesViewController.h"

@interface CategoriesViewController ()
@property (assign, nonatomic) NSInteger category1Number;
@property (assign, nonatomic) NSInteger category2Number;
@property (assign, nonatomic) NSInteger category1SelectedNumber;
@property (assign, nonatomic) NSInteger category2SelectedNumber;
@end

@implementation CategoriesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated{
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
    self.navigationItem.backBarButtonItem = backButton;
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.png"]];
    [self buttonsInitiation];
}

- (void) buttonsInitiation{
    [_category1 setTitle:@"НОВЫЙ Завет" forState:UIControlStateNormal];
    [_category2 setTitle:@"ВетхиЙ Завет" forState:UIControlStateNormal];

    _category1.layer.cornerRadius = 5;
    _category1.layer.borderWidth = 0.2;
    _category1.clipsToBounds = YES;
    _category1.titleLabel.font = [UIFont fontWithName:@"BebasNeueBold" size:34];
    _category1.contentEdgeInsets = UIEdgeInsetsMake(6, 0, 0, 0);

    _category2.layer.cornerRadius = 5;
    _category2.layer.borderWidth = 0.2;
    _category2.clipsToBounds = YES;
    _category2.titleLabel.font = [UIFont fontWithName:@"BebasNeueBold" size:34];
    _category2.contentEdgeInsets = UIEdgeInsetsMake(6, 0, 0, 0);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Buttons

- (IBAction)button1:(id)sender{
    _category1SelectedNumber = 1;
    [[NSUserDefaults standardUserDefaults]setInteger:_category1SelectedNumber forKey:@"MainCategorySaved"];
}
- (IBAction)button2:(id)sender{
    _category1SelectedNumber = 2;
    [[NSUserDefaults standardUserDefaults]setInteger:_category1SelectedNumber forKey:@"MainCategorySaved"];
}

@end

1 个答案:

答案 0 :(得分:0)

问题出在第二个屏幕上的几个按钮中。当我删除它们都变得很好。

Low frame rate during UINavigationController push transition