2013-12-10 109 views
-1

我有一個表設置,從一個plist文件接收數據,一旦你點擊一個tableview單元格,它會帶你到一個視圖控制器,顯示內容。我想在該視圖控制器的頂部有一個UIImageView,它從plist中加載。
我會如何去做呢?UIImageView從Plist

+0

什麼數據從你的plist中來嗎?圖像文件的名稱/位置? – zeantsoi

+0

你到目前爲止嘗試過什麼? – Tirth

+0

http://stackoverflow.com/questions/10846620/ios-load-image-from-plist-file可以在這裏檢查 – 012346

回答

0

你可以像這樣找回plist。

NSString *path = [[NSBundle mainBundle] pathForResource:@"Name" ofType:@"plist"]; 
NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 

NSArray* allmyKeys = [myDictionary allValues]; 
0

實現你正在尋找什麼的正確方法取決於你plist包含的信息。 假設您的plist是一個簡單的路徑,圖像資產列表,你可以添加以下有問題的視圖控制器的viewDidLoad功能:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"nameOfPList" ofType:@"plist"]; 
    NSArray *contentArray = [NSArray arrayWithContentsOfFile:plistPath]; 

    NSString *pathToFile = [contentArray objectAtIndex:0]; // Assumes plist contains paths to images 
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToFile]; 

    UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 

    [self.view addSubview:imageView]; // Add the newly instantiated UIImageView to the controller's view 
}