0

我一直在寻找我的问题的答案。你看我有一个 UIActionSheet 并且当用户尝试按下他们不应该按下的按钮时我将其关闭:它工作得很好,但我试图触发 UIAlert 让用户知道当前操作已经停止,他们需要按“继续”...我的问题出在我的 - (void) actionSheet .... actionSheet 未调用该方法或 buttonIndex 设置不正确。

。H

#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

这是代码UIActionSheetUIAlertView请帮助。这项工作已经逾期两周了。

.m

-(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...它不想显示。

非常感谢可以提供帮助的人!问候,

4

2 回答 2

1

您需要通过以下方式将您的委托设置为您的视图控制器(您希望接收操作表委托方法的对象):

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Play not Allowed during Record" 
    delegate:self 
    cancelButtonTitle:@"Cancel" 
    destructiveButtonTitle:@"Continue" 
    otherButtonTitles:nil];
于 2013-05-20T03:47:12.910 回答
1

您的 actionSheet 代表为零,您没有设置您的代表。

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Play not Allowed during Record" delegate:self cancelButtonTitle:@"Cancel"  destructiveButtonTitle:@"Continue" otherButtonTitles:nil];
[actionSheet showInView: self.view];
于 2013-05-20T03:47:40.887 回答