0

在这段代码中,用户在 ImageViewController 中获取并显示一张照片(现在提供),添加一个标题,然后将照片和标题传递给 MTViewcontroller,在那里它被制作成 pdf。我已经解决了 PDF 部分,但在 segue 中苦苦挣扎。感谢任何指导。我找不到像这样的例子。

ImageViewController.h

#import <UIKit/UIKit.h>
@interface ImageViewController : UIViewController
{
    NSURL *url;
    UIImage *imageRoll;
}
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) IBOutlet UITextField *enterCaption;
- (IBAction)Button:(id)sender;
@end

ImageViewController.m 不确定我是否正确处理了 imageRoll,并且找不到正确的 segue 格式。一旦用户提交了它会segue到PDF控制器的标题。但是,考虑到segue,键盘会释放吗?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Since iPhone simulator doesn't have photos, load and display a placeholder image
    NSString *fPath = [[NSBundle mainBundle] pathForResource:@"IMG_3997" ofType:@"jpg"];
    url = [NSURL fileURLWithPath:fPath];
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
    UIImage *imageRoll = [UIImage imageWithContentsOfFile:fPath];
}

// User provides a caption for the image
- (IBAction)Button:(id)sender {
    NSString *caption = enterCaption.text;
    [self performSegueWithIdentifier:@"showPDF" sender:sender];
    MTViewController *vc1 = [segue destinationViewController];
    vc1.photoCaption = caption;
    MTViewController *vc2 = [segue destinationViewController];
    vc2.photoImage = imageRoll;
}
//Dismiss Keyboard
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

MTViewController.h

#import <UIKit/UIKit.h>
#import "ReaderViewController.h"
@interface MTViewController : UIViewController <ReaderViewControllerDelegate>
@property(nonatomic, assign) NSString *photoCaption;
@property(nonatomic, assign) UIImage *photoImage;
- (IBAction)didClickMakePDF:(id)sender;
@end

MTViewController.m 我是否正确传递并使用了 photoCaption 和 photoImage?

- (IBAction)didClickMakePDF {
    [self setupPDFDocumentNamed:@"NewPDF" Width:850 Height:1100];

    [self beginPDFPage];

    CGRect textRect = [self addText:photoCaption
                          withFrame:CGRectMake(kPadding, kPadding, 400, 200) fontSize:48.0f];

    CGRect blueLineRect = [self addLineWithFrame:CGRectMake(kPadding, textRect.origin.y + textRect.size.height + kPadding, _pageSize.width - kPadding*2, 4) 
                                       withColor:[UIColor blueColor]];

    UIImage *anImage = [UIImage imageNamed:@"photoImage"];
    CGRect imageRect = [self addImage:anImage 
                              atPoint:CGPointMake((_pageSize.width/2)-(anImage.size.width/2), blueLineRect.origin.y + blueLineRect.size.height + kPadding)];

    [self addLineWithFrame:CGRectMake(kPadding, imageRect.origin.y + imageRect.size.height + kPadding, _pageSize.width - kPadding*2, 4) 
                 withColor:[UIColor redColor]];

    [self finishPDF];

}
4

1 回答 1

0

更新:

您应该使用self.xxx = xxx将其保存在一种方法中,然后使用self.xxx. 例如,您应该使用

self.imageRoll = [UIImage imageWithContentsOfFile:fPath];

imageRoll而不是在你的代码中声明一个新的。你的标题也是如此。

您使用 segue 的方式不正确。

你打电话的方式[self performSegueWithIdentifier:@"showPDF" sender:sender];是正确的。但是你可以在

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showPDF"]) {
        MTViewController *vc1 = [segue destinationViewController];
        vc1.photoCaption = self.caption;
        vc1.photoImage = self.imageRoll;
    }
}
于 2013-06-06T07:36:47.733 回答