Ios 呈现UIViewController时引入的延迟
我正在开发一个应用程序,在该应用程序中,我使用Ios 呈现UIViewController时引入的延迟,ios,uitableview,uiviewcontroller,storyboard,segue,Ios,Uitableview,Uiviewcontroller,Storyboard,Segue,我正在开发一个应用程序,在该应用程序中,我使用[self-performsguewithidentifier:@“newViewSegue”发送方:self]从另一个应用程序演示新的UIViewController 在newUIViewController中,我正在初始化我的视图元素,并以编程方式向其中添加UITableView 但是,当我调用此performsguewithidentifiernewUIViewController时,我尝试在新UIViewController的viewDidL
[self-performsguewithidentifier:@“newViewSegue”发送方:self]从另一个应用程序演示新的UIViewController
代码>
在newUIViewController
中,我正在初始化我的视图元素,并以编程方式向其中添加UITableView
但是,当我调用此performsguewithidentifier
newUIViewController
时,我尝试在新UIViewController
的viewDidLoad
和[self-performsguewithidentifier:@“newViewSegue”发送方:self]之前登录代码>语句两个语句都立即执行,但视图在一段时间间隔后显示
我的ViewDidLoad
方法如下:
-(void)viewDidLoad{
sharedObject=[SingleToneClass sharedManager];
selectedButtonTag=-1;
initFlag=0;
NSLog(@"End %@",[NSDate date]);
backgroundView.backgroundColor=[self hexToUiColor:@"E7E7E7"];
[mondayDateButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//set colour for all 7days buttons
[mondayDateButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
//Set font for all days button
[mondayButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//set title colour
[mondayButton.titleLabel setFont:[UIFont systemFontOfSize:12]];
//set font
//Changing image Color
//Home Button
[homeButton.titleLabel setFont:[UIFont fontWithName:kFontAwesomeFamilyName size:40]];
[homeButton setTitleColor:[self hexToUiColor:sharedObject.secondaryHexColorCode] forState:UIControlStateNormal];
[homeButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-home"] forState:UIControlStateNormal];
//Back Button
[backButton.titleLabel setFont:[UIFont fontWithName:kFontAwesomeFamilyName size:27]];
[backButton setTitleColor:[self hexToUiColor:sharedObject.secondaryHexColorCode] forState:UIControlStateNormal];
[backButton setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-chevron-left"] forState:UIControlStateNormal];
//Next Week Button
[nextWeek.titleLabel setFont:[UIFont fontWithName:kFontAwesomeFamilyName size:20]];
[nextWeek setTitleColor:[self hexToUiColor:sharedObject.secondaryHexColorCode] forState:UIControlStateNormal];
[nextWeek setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-chevron-right"] forState:UIControlStateNormal];
//Previous Week Button
[previousWeek.titleLabel setFont:[UIFont fontWithName:kFontAwesomeFamilyName size:20]];
[previousWeek setTitleColor:[self hexToUiColor:sharedObject.secondaryHexColorCode] forState:UIControlStateNormal];
[previousWeek setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-chevron-left"] forState:UIControlStateNormal];
[separatorLineView setBackgroundColor:[self hexToUiColor:@"6D6D6D"]];
[selectLabel setTextColor:[self hexToUiColor:@"6D6D6D"]];
[selectLabel setFont:[UIFont boldSystemFontOfSize:13]];
selectLabel.text=[NSString stringWithFormat:@"%@",selectedTitle];
sharedObject.bookADateTitle=selectedTitle;
//make Buttons Rounded
mondayDateButton.clipsToBounds = YES;
mondayDateButton.layer.cornerRadius = mondayDateButton.frame.size.height/2;
NSDate *currentDate;
if (sharedObject.bookDateViewDate.length>0) {
NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc] init];
[dateFormat1 setDateFormat:@"yyyy-MM-dd"];
currentDate=[dateFormat1 dateFromString:sharedObject.bookDateViewDate];
}
else{
currentDate=[NSDate date];
}
[self setDate:currentDate];
[self setDateToLabel:currentDate]; //set formatted date
//create and initialise UITableView
static NSString *cellIdentifier=@"CustomHiddenViewCell";
CustomHiddenViewCell *cell = (CustomHiddenViewCell *)[slotsTableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomHiddenViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
double heightOfTable=(self.view.frame.size.height-backgroundView.frame.size.height);
//creating tableview1
slotsTableView=[[UITableView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y+backgroundView.frame.size.height,self.view.frame.size.width,heightOfTable)];
slotsTableView.scrollEnabled=YES;
slotsTableView.delegate=self;
[slotsTableView flashScrollIndicators];
slotsTableView.dataSource=self;
slotsTableView.bounces=NO;
slotsTableView.showsVerticalScrollIndicator=YES;
slotsTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
[self.view addSubview:slotsTableView];
//add swipe gesture
UISwipeGestureRecognizer *leftSwipRecognizer;
leftSwipRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeRecognizer:)];
[leftSwipRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[slotsTableView addGestureRecognizer:leftSwipRecognizer];
UISwipeGestureRecognizer *rightSwipRecognizer;
rightSwipRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeRecognizer:)];
[rightSwipRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[slotsTableView addGestureRecognizer:rightSwipRecognizer];
[leftWeekRecognizer addTarget:self action:@selector(WeekSwipeRecognizer:)];
[leftWeekRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[rightWeekRecognizer addTarget:self action:@selector(WeekSwipeRecognizer:)];
[rightWeekRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
}
有人能告诉我为什么会出现这种延迟吗?可能是您的代码在主线程之外的其他线程中执行,请将代码移动到主线程中,或者像这样使用GCD
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
});
你的意思是我应该将我的初始化代码从viewDidLoad
添加到dispatch\u async(dispatch\u get\u main\u queue(),^(void){//Run UI Updates})代码>如-(void){dispatch_async(dispatch_get_main_queue(),^(void){//initialization}}}
是的,您可以这样做,也可以使用标识符方法执行操作!我试图使用您的解决方案,但它仍然引入了延迟显示您的did加载方法,您的代码正在生成视图程序。我已使用viewDidLoad
方法更新了我的问题,请检查