警报视图有问题

时间:2013-08-30 23:05:09

标签: ios button if-statement uialertview

我现在无法使用按钮。实际上,用户可以使用相机或照片库拍摄照片,当选择它们时,他们可以通过按下按钮来共享该照片。但是,如果他们在选择照片之前按下共享按钮,则会导致应用程序崩溃。我很好奇我如何处理活动警报,因此如果按下按钮并且没有媒体,它将显示警报消息以及一点振动。如果他们确实选择了图片,则会显示活动表,用户可以从此菜单中共享。菜单工作正常,但我知道if / else语句有缺陷。图片由“_timeSlip”表示。谢谢您的帮助!我的代码如下:

- (IBAction)shareButtonPressed
{
    if (_timeSlip !=nil)
{
    // Issue vibrate
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"No Photo Chosen"
                                                   message: @"Please Select a Photo"
                                                  delegate: self
                                         cancelButtonTitle:@"Cancel"
                                         otherButtonTitles:@"OK",nil];


    [alert show];
    [alert release];
    }
    else {
    // 
    //step 1: set up path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    //step 2: get path for local file
    NSString* path = [documentsDirectory stringByAppendingPathComponent:
                  @"time.png" ];

    //UIImage *localImage = [UIImage imageNamed:@"SDBack.png"];

    UIImage *localImage = _timeSlip;



    REMailActivity *mailActivity = [[REMailActivity alloc] init];


    RESaveToCameraRollActivity *saveToCameraRollActivity = [[RESaveToCameraRollActivity alloc] init];
    REPrintActivity *printActivity = [[REPrintActivity alloc] init];
    RECopyActivity *copyActivity = [[RECopyActivity alloc] init];
     // Compile activities into an array, we will pass that array to
    // REActivityViewController on the next step
    //
    NSArray *activities = @[mailActivity, saveToCameraRollActivity, printActivity,copyActivity];
    // Create REActivityViewController controller and assign data source
    //
    REActivityViewController *activityViewController = [[REActivityViewController alloc]       initWithViewController:self activities:activities];
    activityViewController.userInfo = @{
                                    @"image": localImage,
                                    @"text": @"Time Slip!"
                                    };

   [activityViewController presentFromRootViewController];
}
}

1 个答案:

答案 0 :(得分:1)

根据提供的代码和您的描述,如果_timeslip为nil,您似乎想要显示警报/振动,但如果_timeslip不是nil,则显示警报。此外,崩溃很可能是由于_timeslip在你的“else”语句中为零而引起的。