[英]A UIButton above a UIPickerView
I have a UIPickerView which works correctly, now I want to add a button above it so that I can dismiss it. 我有一个可以正常工作的UIPickerView,现在我想在其上方添加一个按钮,以便将其关闭。
and here is my code where I initiate a UIPickerView as well as its dismiss button: 这是我启动UIPickerView及其关闭按钮的代码:
- (UIPickerView *)creatPickerView {
UIPickerView *tempPickerView = [[[UIPickerView alloc]
initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
tempPickerView.showsSelectionIndicator = YES;
tempPickerView.delegate = self;
tempPickerView.dataSource = self;
UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
[pickerButton setBackgroundImage:[UIImage imageNamed:@"hidePicker.png"]
forState:UIControlStateNormal];
[pickerButton addTarget:self action:@selector(hidePicker)
forControlEvents:UIControlEventTouchUpInside];
[tempPickerView addSubview:pickerButton];
[pickerButton release];
[self.view addSubview:tempPickerView];
return tempPickerView;
}
and it works well on my iPhone 4.3 Simulator, like this: 并在我的iPhone 4.3 Simulator上运行良好,如下所示:
apparently there is a button on the upper right of the pickerView, 显然在pickerView的右上方有一个按钮,
problem is, when I run the app in my device - a 5.0.1 iPhone4 and a 4.2.1 iTouch, the button is missed like it has never been added to the pickerView. 问题是,当我在设备上运行该应用程序-5.0.1 iPhone4和4.2.1 iTouch时,缺少了按钮,因为它从未添加到pickerView中。
Can anyone help me with this? 谁能帮我这个?
Thanks a lot and a lot! 非常感谢!
I found the reason, it seems the png has some problem, 我找到了原因,看来png有问题,
after I change another png, it comes up in the screen! 在我更改另一个png之后,它会出现在屏幕上!
but the real problem is that I place the button outside of the pickerView which results in the button's untouchableness. 但是真正的问题是我将按钮放置在pickerView之外,这导致按钮无法触摸。
But anyway the pickure is only a small problem. 但是无论如何,挑剔只是一个小问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.