【发布时间】:2023-03-14 11:05:02
【问题描述】:
当我在选择器视图上添加工具栏时,工具栏按钮不起作用。它适用于 iOS 6,但不适用于 iOS 7。
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0 ,0, 320, 44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(handleDone)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(handleCancel)];
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self
action:nil];
[toolBar setItems:[NSArray arrayWithObjects:cancelButton, flexible, doneButton, nil] animated:YES];
[pikerView addSubview:toolBar];
【问题讨论】:
-
使用uiview,在uiview里面添加toolbar和uipickerview。
-
stackoverflow.com/questions/20883388/… 看看我给出的这个答案
-
感谢您的回复,但我想知道为什么会这样。我知道单独查看并单独添加两件事会起作用。 Rushabh 将您的回复作为答案,所以我可以接受它。需要解释上述问题为什么会这样。
标签: ios iphone uibutton uipickerview toolbar