簡體   English   中英

在UINavigationcontroller堆棧中將ViewController推入時,它會變黑

[英]ViewController goes black when pushing it in UINavigationcontroller stack

我有一個UInavigationController堆棧。 RootViewController我有button。 當我單擊按鈕時,將按下一個新的viewcontroller並顯示UIDatePicker 問題是導航到View Controller時顯示日期選擇器1秒鍾,然后突然消失,整個屏幕變為黑色。 這是代碼

//rootviewcontroller 
- (IBAction)dateAction:(id)sender 
{
    self.another = [[AnotherViewController   alloc]initWithButtonWithTag:self.dateButton.tag andDelegate:self];
    [self.navigationController pushViewController:self.another animated:YES];
    self.another.navigationItem.title = @"DateName";
}



//second viewcontroller

- (void)viewDidload 
{
    self.pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 325, 300)];
    [self.pickerView addTarget:self action:@selector(datePickerDidChangeDate:)  forControlEvents:UIControlEventValueChanged];

    self.pickerView.datePickerMode = UIDatePickerModeDate;
    self.pickerView.hidden = NO;
    self.pickerView.date = [NSDate date];

    self.formatter = [[NSDateFormatter alloc] init];

    self.formatter.dateStyle = NSDateFormatterLongStyle;

    [self.view addSubview:self.pickerView];
}

幫助將不勝感激

試試這個代碼...

第一視圖控制器

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSArray *temp=[NSArray arrayWithObjects:@"button1" ,@"button2" ,@"button3",nil];
    for (int i=0; i<=2; i++)
    {
        _likeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [_likeBtn setFrame:CGRectMake(20+(i*80), 220, 102, 20 )];
        [_likeBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [_likeBtn setTitle:[temp objectAtIndex:i] forState:UIControlStateNormal];
        [_likeBtn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
        [_likeBtn setTag:i];
        [self.view addSubview:_likeBtn];
    }

    // Do any additional setup after loading the view from its nib.
}
- (IBAction)action:(id)sender

{
    UIButton *button=(UIButton *)sender;
    NSLog(@"%d",button.tag);
    secViewController *obj = [[secViewController alloc]init];
    obj.tagValue=button.tag;
    [self.navigationController pushViewController:obj animated:YES];
    obj.navigationItem.title = @"DateName";
}

第二個視圖.h文件

 @property(nonatomic,assign) NSInteger *tagValue;

.m文件

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSInteger *tag=self.tagValue;

    if (tag==0)
    {
        //tableView
        NSLog(@"tableview");
    }
    else
    {
        //datepicker
        NSLog(@"picker");

          self.pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 325, 300)];
          [self.pickerView addTarget:self action:@selector(datePickerDidChangeDate:)  forControlEvents:UIControlEventValueChanged];
                self.pickerView.datePickerMode = UIDatePickerModeDate;
            self.pickerView.hidden = NO;
           self.pickerView.date = [NSDate date];
          self.formatter = [[NSDateFormatter alloc] init];
            self.formatter.dateStyle = NSDateFormatterLongStyle;
            [self.view addSubview:self.pickerView];
    }

    // Do any additional setup after loading the view from its nib.
}
-(void)datePickerDidChangeDate:(id)sender
{
    NSLog(@"%@",self.pickerView.date);
}

讓我知道是否已注冊...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM