2011-07-27 308 views
2

我有这样的代码从NSMutableArray的NSDictionary中获取NSString,但问题是它没有显示正确。 下面是代码:ActionSheet没有正确显示

UIActionSheet *playingSheet = [[UIActionSheet alloc] initWithTitle:@"Hi" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 
    for(NSDictionary *dict in accounts) { 
     NSString *name = [dict objectForKey:@"Name"]; 
     [playingSheet addButtonWithTitle:name]; 
    } 
    [playingSheet showInView:self.view]; 
    [playingSheet release]; 

的问题是在我的情况,self.view是parentView的子视图,并从厦门国际银行加载且无法全屏显示。所以问题是我的操作表就像iPhone屏幕宽度的一半,甚至不能触摸屏幕的底部。 在我的情况下,我如何修复它,使其最上面的视图(以便用户可以正确看到它),以及常规actionSheet应该看起来的方式?

谢谢!

编辑:这是修复:

[playingSheet showInView:[UIApplication sharedApplication].keyWindow]; 

回答

3

您需要设置动作片的帧

[playingSheet setFrame:CGRectMake(0, theHeightYouWant, 320, yourDesiredHeight)]; 

“theHeightYouWant”是,你必须在动作片换档向上/向下放置在正确的位置在屏幕上高度。您可以通过反复试验来改变这一点。例如,如果您的self.view位于屏幕的下半部分,则“theHeightYouWant”将为负值!

+0

不确定如果每次按钮的数量发生变化,我将如何设置操作页的高度。 –

+1

修正了它: [playingSheet showInView:[UIApplication sharedApplication] .keyWindow]; –

+0

不错...我不知道这种方式!无论如何,你可以使“yourDesiredHeight”随着按钮的数量而变化,其中每个按钮增加一个特定的数量给“yourDesiredHeight”。与“theHeightYouWant”类似。 – tipycalFlow

2

根据你的代码是如何设置的,你可以尝试使用self.parentViewController.viewself.view.windowself.view.superview,或任何的各种东西。如果您想要更详细的答案,您需要提供更多信息。

+0

没有3个工作。它会在控制台(SIGABRT)中引发此错误:***终止应用程序,由于未捕获的异常'NSInternalInconsistencyException',原因:'无效参数不令人满意:view!= nil' 我应该尝试其他什么? *** –

+0

我不知道,因为我不知道你的应用程序是如何设置的。 – jtbandes