我試圖鑽取一些UITableViewControllers
,最終得到一個基於用戶選擇的部分和行加載的pdf文件。我試圖將部分和行信息傳遞給PDFViewController
(有效),但我無法將選定的部分和行信息傳遞給UIScrollView
,它實際上加載了PDF。我試圖在PDFScrollView
被實例化時設置一個屬性,但是當加載PDFScrollView
時,該值不會被保留。從PDFViewController.m試圖從UIViewController分配一個屬性到UIScrollView類
#import "PDFViewController.h"
#import "PDFScrollView.h"
#import "ProtocolDetailViewController.h"
@implementation PDFViewController
@synthesize detailIndexRow;
@synthesize detailIndexSection;
- (void)loadView {
[super loadView];
// Log to check to see if detailIndexSection has correct value
NSLog(@"pdfVC section %d", detailIndexSection);
NSLog(@"pdfVc row %d", detailIndexRow);
// Create PDFScrollView and add it to the view controller.
PDFScrollView *sv = [[PDFScrollView alloc] initWithFrame:[[self view] bounds]];
sv.pdfIndexSection = detailIndexSection;
[[self view] addSubview:sv];
}
現在
代碼從PDFScrollView.m
其中pdfIndexSection
不會detailIndexSection
#import "PDFScrollView.h"
#import "TiledPDFView.h"
#import "PDFViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation PDFScrollView
@synthesize pdfIndexRow;
@synthesize pdfIndexSection;
- (id)initWithFrame:(CGRect)frame
{
// Check to see value of pdfIndexSection
NSLog(@"PDF section says %d", pdfIndexSection);
NSLog(@"PDF row says %d", pdfIndexRow);
if ((pdfIndexSection == 0) && (pdfIndexRow == 0)) {
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"cardiacarrestgen.pdf" withExtension:nil];
pdf = CGPDFDocumentCreateWithURL((__bridge_retained CFURLRef)pdfURL);
}
else if ((pdfIndexSection == 0) && (pdfIndexRow == 1)) {
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"cardiacarrestspec.pdf" withExtension:nil];
pdf = CGPDFDocumentCreateWithURL((__bridge_retained CFURLRef)pdfURL);
}
pdfIndexSection
和pdfIndexRow
保留在上面的代碼分配給它的值都是int
和回報0
無論在didSelectRowAtIndexPath
中選擇了哪一部分或哪一行。
所以兩個問題:
爲什麼當我在
ViewController
一個int值賦給sv.pdfIndexSection
,是不是保留在ScrollView
價值。有沒有更好的方法來實現這個概念?
謝謝!這是非常有意義的,並糾正了這個問題。非常感激! – blueHula