Wednesday, May 29, 2013

UIActionSheet showFromRect inView animated example in Objective C (iOS).

UIActionSheet showFromRect inView animated

Displays an action sheet that originates from the specified view.

- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated

Parameters of [UIActionSheet showFromRect inView animated]
rect
The portion of view from which to originate the action sheet.
view
The view from which to originate the action sheet.
animated
Specify YES to animate the presentation of the action sheet or NO to present it immediately without any animation effects.

Discussion of [UIActionSheet showFromRect inView animated]
On iPad, this method displays the action sheet in a popover whose arrow points to the specified rectangle of the view. The popover does not overlap the specified rectangle.

UIActionSheet showFromRect inView animated example.
-(void)accessoryPressed:(id)sender{
    //Omitted unnecessary objects

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:titleString delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Upload", nil];
    //actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.tag = ((UIButton*)sender).tag;
    [actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES];
}

Example of [UIActionSheet showFromRect inView animated].
UIDatePicker * pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 270, 220)];
pickerView.datePickerMode = UIDatePickerModeDate;

UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];  

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet addSubview:pickerView];
[actionSheet showFromRect:button.frame inView:button.superview animated:YES];
[actionSheet release];

UIActionSheet showFromRect inView animated example.
CGRect cellRect = cell.bounds;
cellRect.size.width = cell.frame.size.width * 2;
cellRect.origin.x = -(cell.frame.size.width + 10.0);
[_actionSheet showFromRect:cellRect inView:cell animated:YES];

End of UIActionSheet showFromRect inView animated example article.