我的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];
}但它不会对此置之不理。我不想改变我的设计和任何按钮的位置。我该怎么办?
发布于 2012-12-01 18:16:14
-(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
}发布于 2014-01-10 04:34:16
从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
}
}发布于 2012-12-01 18:01:46
您必须将其添加到您的.h文件中。
<UIActionSheetDelegate>还要将此行添加到您的.m文件。
actionSheet.delegate = self;让我知道,这是工作或没有。如果有效,接受它作为正确的答案。
https://stackoverflow.com/questions/13658244
复制相似问题