Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UIAlertView上添加UISlider_Ios_Objective C_Uialertview - Fatal编程技术网

Ios 在UIAlertView上添加UISlider

Ios 在UIAlertView上添加UISlider,ios,objective-c,uialertview,Ios,Objective C,Uialertview,我想在UIAlerView上添加一个UISlider,但我无法这样做。我也用谷歌搜索了一下,但我只找到了两个答案,两个答案都没有显示任何结果。这里是我在项目中发现并应用的代码: UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"msg" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil]; aler

我想在
UIAlerView
上添加一个
UISlider
,但我无法这样做。我也用谷歌搜索了一下,但我只找到了两个答案,两个答案都没有显示任何结果。这里是我在项目中发现并应用的代码:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"msg" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
alertView.title =  @"title";

CGRect frame = CGRectMake(alertView.frame.origin.x+10,alertView.frame.origin.y+20,100, 100.0);
UISlider *slider = [[UISlider alloc] initWithFrame:frame];
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[slider setBackgroundColor:[UIColor clearColor]];
slider.minimumValue = 0.0;
slider.maximumValue = 10.0;
slider.continuous = YES;
slider.value = 25.0;
[alertView addSubview:slider];
[alertView show];
我认为滑块的框架不合适,这就是为什么它没有被显示的原因。 有人能帮我吗。。。。。
提前感谢您…

您正在警报视图中添加滑块,而不是在警报视图的父视图中添加滑块

因此,帧值将在警报视图中的某个位置添加滑块,结果将隐藏在警报视图中

所以,换掉这条线

CGRect frame = CGRectMake(alertView.frame.origin.x+10,alertView.frame.origin.y+20,100, 100.0);

UIAlertView也是一个UIView。实际上,您可以在其中添加子视图。但是

UIAlertView类按原样使用,不支持子类化。此类的视图层次结构是私有的,不能修改。


因此,最好使用充当alertview的自定义视图。

由于iOS7,您无法将
UIView
添加到
UIAlertView
中。您必须(或使用GitHub/CocoaControls/…)自己的UIAlertView-like。非常感谢您的朋友,但它仍然不可见(
CGRect frame = CGRectMake(10,20,100, 100.0);