2013-04-09 99 views
0

好吧,所以我一直在研究這個錯誤2個小時,並看過所有的鏈接,我可以找到,也有我的問題。我試圖在UIScrollView中放置UIImageView,然後在屏幕上顯示滾動視圖。當我嘗試這樣做時,不會顯示任何內容。首先,我認爲imageview的沒有必須一要顯示的圖像,所以我僅僅通過增加的ImageView屏幕UIScroll查看不顯示UIImageView

[self.view addSubview:mapDisplay]; 

和圖像顯示測試這一點,但我仍然無法得到的圖像顯示,當我將其放在滾動視圖中。

任何幫助將被appricated。

.h文件中

#import <UIKit/UIKit.h> 
#import "FloorsContainer.h" 
@interface FloorMapViewController : UIViewController { 
    UIImage* mapToShow; 
    IBOutlet UIImageView *mapDisplay; 
    IBOutlet UIScrollView *mapScrollView; 
} 
@property(nonatomic, retain) UIImageView *mapDisplay; 
@property(nonatomic, retain) UIScrollView *mapScrollView; 
-(void)setMapImage:(UIImage *) newMap; 
@end 

.m文件

@interface FloorMapViewController() 
@end 
@implementation FloorMapViewController 
@synthesize mapDisplay, mapScrollView; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initializatio 
    } 
    return self; 
} 
-(void)setMapImage:(UIImage *) newMap { 
    if (newMap != NULL) { 
     mapToShow = newMap; 
    } 
}   
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [super viewDidLoad]; 
    if (mapToShow != NULL) { 
     //declare both scrollview and image view 
     mapDisplay =[[UIImageView alloc] init]; 
     mapScrollView = [[UIScrollView alloc] init]; 
     //set size of both 
     mapDisplay.frame = CGRectMake(0, 0, 320, 480); 
     [mapScrollView setContentSize:CGSizeMake(mapDisplay.frame.size.width, mapDisplay.frame.size.height)]; 
     mapScrollView.contentMode = (UIViewContentModeScaleAspectFit); 
     mapScrollView.clipsToBounds = YES; 
     //set the picture 
     [mapDisplay setImage:[UIImage imageNamed:@"Sci.jpg"]]; 
     //set zoom 
     [mapScrollView setMinimumZoomScale:1.0]; 
     [mapScrollView setMaximumZoomScale:2.0]; 
     //combine the two 
     [mapScrollView addSubview:mapDisplay]; 
     //set scroll pane to main window 
     [self.view addSubview:mapScrollView]; 
    } 
} 

它不進入if語句。我相信這與我如何連接圖像視圖和滾動視圖有關。 (我對iOS開發仍然有點新,但是我很快學習)。任何幫助將非常感激。

回答

0

如果你認爲它是與你如何連接它那麼問題很可能位於您的故事板或筆尖文件。確保你只有一個插座連接到每個屬性,並且不要讓你的插座超載。嘗試刪除它們並重新將您的插座重新連接到各個屬性。

另外,@properties應該

@property(nonatomic, retain) IBOutlet UIImageView *mapDisplay; 
@property(nonatomic, retain) IBOutlet UIScrollView *mapScrollView;