Reputation: 12444
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];
Upvotes: 2
Views: 3345
Reputation: 7644
You need to set the frame of the action sheet as
[playingSheet setFrame:CGRectMake(0, theHeightYouWant, 320, yourDesiredHeight)];
"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!
Upvotes: 3
Reputation: 118671
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.
Upvotes: 2