ActionSheet 未正确显示
我有这段代码可以从 NSMutableArray 的 NSDictionary 获取 NSStrings,但问题是它显示不正确。 代码如下:
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 的子视图,是从XIB 加载的,并且不是全屏的。所以问题是我的操作表就像 iPhone 屏幕宽度的一半,甚至没有接触屏幕底部。 就我而言,我将如何修复它,使其成为最顶层的视图(以便用户可以正确地看到它),以及常规 actionSheet 的外观?
谢谢!
编辑:这是修复:
[playingSheet showInView:[UIApplication sharedApplication].keyWindow];
I have this code to get NSStrings from an NSDictionary from an NSMutableArray but the problem is that it does not show right.
Here is the code:
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];
The problem is in my case, self.view is a subview of a parentView and is loaded from an XIB and is not full screen. So the problem is my action sheet is like half the width of the iPhone's screen and it is not even touching the bottom of the screen.
In my case, how would I fix it so its the top most view (so users can see it properly), and the way a regular actionSheet is supposed to look?
Thanks!
Edit: This was the fix:
[playingSheet showInView:[UIApplication sharedApplication].keyWindow];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将操作表的框架设置为
“theHeightYouWant”,您必须向上/向下移动操作表才能将其放置在屏幕上的正确位置。您可以通过反复试验来更改此设置。例如,如果您的 self.view 在屏幕的下半部分,“theHeightYouWant”将为负数!
You need to set the frame of the action sheet as
"theHeightYouWant" is the height by which you must shift the action-sheet upwards/downwards to put it in the right position on the screen. You can change this by trial and error. For example, if your self.view is in the lower half of the screen, "theHeightYouWant" will be negative!
根据代码的设置方式,您可以尝试使用
self.parentViewController.view
、self.view.window
、self.view.superview
,或任何各种各样的事情。如果您想要更详细的答案,您需要提供更多信息。Depending how your code is set up, you could try using
self.parentViewController.view
,self.view.window
,self.view.superview
, or any of a variety of things. You need to provide more information if you want a more detailed answer.