[英]How to dismiss the actionsheet in tableviewcell when i tap on the view in ios
這是我的Code.Xcode的新手,當我點擊tableview單元格時會得到UIActionSheet。要關閉UIActionSheet,我使用了UITapGestureRecognizer。它對我不起作用。
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
UILabel *lbl = (UILabel *)[cell.contentView viewWithTag:2];
NSLog(@"cell text label =%@",lbl.text);
_StoreNameobj = lbl.text;
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Store Maintenance Action"
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:nil
otherButtonTitles:@"Show Store Details",@"Navigate to Store",@"Edit Store Nickname",@"Delete Store", nil];
actionSheet.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)];
[lbl addGestureRecognizer:tapGesture];
[cell.contentView addSubview:lbl];
}
- (void)tapOut{
//dismiss the action sheet here
[actionSheet removeFromSuperview];
}
任何幫助都是可以的。在此先感謝!
我認為您不需要手動刪除操作表。 默認情況下,動作表會在點擊時退出。 我認為沒有必要采取跳格手勢。
顯示動作表,
[actionSheet showInView:self.view];
因此,當您按下任何按鈕時,它將自動關閉
要在UITableViewCell上查看UIActionSheet,請應用此代碼
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Your Title:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
@"button title1", nil];
[popup show];
}
添加TapGesture
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UITapGestureRecognizer *tapp = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HideActionSheet:)];
[tapp setNumberOfTapsRequired:1];
tapp.cancelsTouchesInView = NO;
[self.view.window tapp];
[tapp release];
}
HideActionSheet代碼:
- (void) HideActionSheet:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint location = [sender locationInView:nil];
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil])
{
[self.view.window removeGestureRecognizer:sender];
[self dismissModalViewControllerAnimated:YES];
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.