在这段代码中,用户在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。我不确定我是否正确处理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。我是否通过并正确使用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];
}
updated:
您应该使用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;
}
}