我一直在寻找我的问题的答案。你看我有一个UIActionSheet,当用户试图按下一个他们不应该按下的按钮时,我正在关闭它:它工作得很好,但我试图触发UIAlert让用户知道当前的操作已经停止,他们需要按“继续”...我的问题在我的 - (void)actionSheet ....该方法未被actionSheet调用或buttonIndex未正确设置。
#import <UIKit/UIKit.h>
@interface DVRRemote : UIViewController <UIActionSheetDelegate>
@property (nonatomic) BOOL pwrOff;
@property (nonatomic) BOOL dvrState;
@property (nonatomic) BOOL playState;
@property (nonatomic) BOOL rcdState;
@property (nonatomic) BOOL rcdPlay;
@property (strong, nonatomic) IBOutlet UISwitch *pwrSwitch;
@property (strong, nonatomic) IBOutlet UITextField *dvrStateLbl;
@property (strong, nonatomic) IBOutlet UITextField *PwrLbl;
- (IBAction)buttonPressed:(UIButton *)sender;
- (IBAction)pwrPressed:(UISwitch *)sender;
@end
以下是代码UIActionSheet
和UIAlertView
...请帮忙。这项工作已经过了两周了。
-(IBAction)buttonPressed:(UIButton*)sender
{
if (_pwrOff == NO)
{
if (_rcdPlay == NO)
{
if ([sender.currentTitle isEqual: @"Play"])
{
_dvrStateLbl.text = @"Playing";
_playState = YES;
_rcdState = NO;
}
}
else
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Play not Allowed during Record" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Continue" otherButtonTitles:nil];
[actionSheet showInView: self.view];
}
}
}
-(void)actionSheet:(UIActionSheet*)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [actionSheet cancelButtonIndex])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Playing" message:[NSString stringWithFormat:@"Recording stopped"] delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
}
}
请注意:我已在每个buttonIndex == 0, == 1, == 2
下编码警报......它不想显示。
非常感谢能够提供帮助的人! 问候,
答案 0 :(得分:1)
您需要通过以下方式将代理设置为视图控制器(您希望接收操作表委托方法的对象):
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Play not Allowed during Record"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Continue"
otherButtonTitles:nil];
答案 1 :(得分:1)
你的actionSheet委托是nil,你没有设置你的委托。
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Play not Allowed during Record" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Continue" otherButtonTitles:nil];
[actionSheet showInView: self.view];