UIButton的IBAction仅在第一次点击时才有效

时间:2015-12-21 16:59:40

标签: ios uibutton ibaction

使用Apple的模板“Tabbed Bar Banner”我发现其中一个视图中的按钮仅在我按下它时第一次起作用。

如果iPhone连接到Xcode以运行应用程序,它的效果很好。一旦我拆下电缆,按钮就会停止工作。

- (IBAction)sendData:(id)sender {

            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePicker.allowsEditing = YES;
            [self presentViewController:imagePicker animated:YES completion:nil];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        [self dismissViewControllerAnimated:YES completion:^{
            [self openEmail];
        }];

    }
-(IBAction) openEmail {

    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    [mailComposer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [mailComposer setToRecipients:[NSArray arrayWithObjects:@"*******", nil]];
        [mailComposer setSubject:self.nameTextField.text];
        NSLog(@"self.nameTextField.text = %@", *********);
        [mailComposer setMessageBody:@"******r" isHTML:NO];
        [mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

        NSString *path = [[NSBundle mainBundle] pathForResource:@"Answer" ofType:@"plist"];
        NSData *myData = [NSData dataWithContentsOfFile:path];
        [mailComposer addAttachmentData:myData mimeType:@"application/xml" fileName:@"Answer.plist"];
        NSData *imageData = UIImageJPEGRepresentation(selectedImage, 0.5);
        [mailComposer addAttachmentData:imageData  mimeType:@"image/jpg"   fileName:[NSString stringWithFormat:@"%@.jpg",*********]];

        [self composeCSV];

        NSString *fileName = [file lastPathComponent];
        [mailComposer addAttachmentData:[NSData dataWithContentsOfFile:file] mimeType:@"text/csv" fileName:fileName];

        [self presentViewController:mailComposer animated:YES completion:nil];
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)composeCSV{
    NSMutableString *mainString = [[ NSMutableString alloc]initWithString:@"++;++;++;++;...\n"];

    [mainString appendFormat:@"%@;\n",...];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    file = [NSString stringWithFormat:@"%@/%@.csv",documentsDirectoryPath,******];
    NSError *csVerror= NULL;
    BOOL written = [mainString writeToFile:file atomically:YES encoding:NSUTF8StringEncoding error:&csVerror];
    if (!written)  {
        NSLog( @"Writing failed, error = %@",csVerror);
    }else {
        NSLog(@"Data saved! File path = %@",file);
    }

}

0 个答案:

没有答案