【问题标题】:UIImageView From Plist来自 Plist 的 UIImageView
【发布时间】:2013-12-10 04:52:55
【问题描述】:

我设置了一个表格,它从 plist 文件接收数据,一旦您点击表格视图单元格,它会将您带到显示内容的视图控制器。我想在从 plist 加载的视图控制器顶部有一个 UIImageView。
我该怎么做呢?

【问题讨论】:

  • 什么数据来自您的 plist?图片文件的名称/位置?
  • 到目前为止你尝试了什么?
  • @user2843105,这个问题是大约一个月前提出的。您有机会查看所提供的任何答案吗?
  • @user2843105,这方面的最新消息是什么?提供的任何答案有帮助吗?

标签: ios objective-c uitableview uiimageview plist


【解决方案1】:

您可以像这样检索 plist。

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

NSArray* allmyKeys = [myDictionary  allValues];

【讨论】:

    【解决方案2】:

    实现您所寻求的正确方法取决于您的 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多