2014-10-22 59 views
0

我向UIAlertController添加了選擇器視圖,但它的觸摸不能在整個選擇器上工作,它只是在選擇器的某個特定部分工作。請大家幫我出這個UIAlertController觸摸不能正常工作

代碼如下:

if (IS_IOS8_AND_UP) { 

    UIAlertController * searchActionSheet=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet]; 

    [searchActionSheet.view setBounds:CGRectMake(8, 180, self.viewSize.width, sheetHeight)]; 

// aView.frame = CGRectMake(100,100,aView.frame.size.width,aView.frame.size.height);

//yourView represent the view that contains UIPickerView and toolbar 

[searchActionSheet.view addSubview:aView]; // [[self topViewController] .view addSubview:searchActionSheet.view]; [[self topViewController] presentViewController:searchActionSheet animated:YES completion:nil];

} 
else 
{ 
    _actionSheet = [[UIActionSheet alloc] initWithTitle:paddedSheetTitle delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 
    [_actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 
    [_actionSheet addSubview:aView]; 
    [self presentActionSheet:_actionSheet]; 
    _actionSheet.bounds = CGRectMake(0, 0, self.viewSize.width, sheetHeight); 
} 

看到圖像enter image description here

+0

UIAlertController的文檔說「這個類的視圖層次是私有的,不能修改。」 – 2015-07-22 09:39:22

回答

0
UIAlertController * searchActionSheet=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet]; 
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil]; 
[searchActionSheet addAction:alertAction]; 
[searchActionSheet addAction:alertAction]; 
[searchActionSheet addAction:alertAction]; 
[searchActionSheet addSubview:picker]; 

添加alertAction目的是alertcontroller正如我上面添加。之後,嘗試將你的選擇器作爲子視圖添加到alertcontroller。

根據需要添加儘可能多的alertAction對象來調整視圖。不知道這是否是正確的方式,但它對我有用。