【发布时间】:2015-11-26 10:47:43
【问题描述】:
我已经在 iOS 8 中创建了我的项目,它工作正常,现在我尝试在 iOS9 中运行。UIButton 没有出现。我以编程方式创建了一个按钮,但它不仅仅出现在 iOS9 中。它在 iOS7 和 iOS8 中运行良好。请看下面的代码。
UIButton *NewOrderButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[NewOrderButton addTarget:self action:@selector(ButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[NewOrderButton setTitle:@"Create" forState:UIControlStateNormal];
NewOrderButton.frame = CGRectMake((self.view.frame.size.width-200)/2,(self.view.frame.size.height+80)/2, 200, 40.0);
[NewOrderButton.layer setBorderWidth:1];
[NewOrderButton.layer setBorderColor:[[UIColor whiteColor] CGColor]];
NewOrderButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[self.view addSubview:NewOrderButton];
如果我调试这段代码,那么按钮就会出现。
【问题讨论】:
-
您在视图控制器上的何处添加了此代码?在 viewDidLoad 方法中?
-
不是
_NewOrderButton它是NewOrderButton -
对不起。请检查我编辑了我的问题
-
@Cong Tran 我在 viewDidAppear 中添加了
-
请检查我的答案。希望对您有所帮助。
标签: ios objective-c uibutton ios9