gpt4 book ai didi

ios - 将 ViewController 插入 UINavigationcontroller 堆栈时变黑

转载 作者:行者123 更新时间:2023-11-29 02:58:49 25 4
gpt4 key购买 nike

我有一个 UINavigationController 堆栈。在 RootViewController 我有按钮。当我单击该按钮时,将推送一个新的 View Controller ,并应显示 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];
}

如果有帮助,我们将不胜感激

最佳答案

试试这个代码...

第一个 View Controller

- (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);
}

让我知道是否满意...

关于ios - 将 ViewController 插入 UINavigationcontroller 堆栈时变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23534064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com