[英]UIActionsheet not dismissing
我的UIActionsheet中有3個按鈕。 我想要一個取消按鈕在其底部。
我還希望所有按鈕都能夠關閉UIActionsheet。
目前,沒有人為我做這項工作。
這是我的顯示方式:
UIActionSheet *actionSheet = nil;
NSArray *otherButtons = nil;
otherButtons = [NSArray arrayWithObjects:@"Button1", @"Button2", @"Button3",
nil];
actionSheet = [[UIActionSheet alloc] initWithTitle:title
delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
for( NSString *btntitle in otherButtons)
{
[actionSheet addButtonWithTitle:btntitle];
}
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
在我的代表中,我這樣做:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//some code
[actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
}
但這並不能消除。 我不想更改任何按鈕的設計和位置。 我該怎么辦?
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
[actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
[self performSelector:@selector(OtherOperations) withObject:nil afterDelay:0.0];
}
-(void)OtherOperations{ //some code
}
從lpgr打開操作表時要小心。 僅在“開始”上打開它,而不在“結束”上打開它。
- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.tblYourVids];
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
NSIndexPath *indexPath = [self.aTable indexPathForRowAtPoint:p];
if (indexPath == nil)
NSLog(@"long press on table view but not on a row");
else {
NSLog(@"long press on table view at row %d", indexPath.row);
self.selectedCell = [self.aTable cellForRowAtIndexPath:indexPath];
DLog(@"open action sheet only once");
[self showActionSheet];
}
} else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
// eat this one
}
}
您必須將此添加到您的.h文件中。
<UIActionSheetDelegate>
還將這一行添加到您的.m文件中。
actionSheet.delegate = self;
讓我知道,這是否有效。 如果可行,將其作為正確答案
只需嘗試使用以下代碼,它就會自動關閉。
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@""
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Printer"
otherButtonTitles: nil];
[sheet showInView:self.view];
[sheet release];
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
}
讓我知道它是否有效
快樂編碼!!!
這不是取消UIActionSheet
的正確方法,首先您必須通過javascipt
禁用默認的UIActionSheet
並通過此Web
http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.