在此代码中,用户在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格式。一旦用户提交了标题,它就会转向PDF控制器。但是,键盘会释放出来吗?
- (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];
}
答案 0 :(得分: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;
}
}