Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用plist显示自定义TableView单元格?_Ios_Xcode_Plist_Tableview - Fatal编程技术网

Ios 使用plist显示自定义TableView单元格?

Ios 使用plist显示自定义TableView单元格?,ios,xcode,plist,tableview,Ios,Xcode,Plist,Tableview,我想在一个表格视图单元格中显示一个小图像和日期,用户可以单击它来显示另一个包含更多信息的视图。所有这些数据都存储在plist(图像、日期和其他数字)中 我似乎不能: 获取要显示在单元格内的图像-我将所有图像添加到Supporting Files文件夹中,并尝试将文件名输入到plist中,但plist不接受 添加用户单击单元格并从plist数据查看更多信息的功能 首先,使用包含字典数组的plist构建“数据库”。这应该是这样的: 创建并NSArray保存此plist: @property (st

我想在一个表格视图单元格中显示一个小图像和日期,用户可以单击它来显示另一个包含更多信息的视图。所有这些数据都存储在plist(图像、日期和其他数字)中

我似乎不能:

  • 获取要显示在单元格内的图像-我将所有图像添加到Supporting Files文件夹中,并尝试将文件名输入到plist中,但plist不接受

  • 添加用户单击单元格并从plist数据查看更多信息的功能

  • 首先,使用包含字典数组的plist构建“数据库”。这应该是这样的:

    创建并
    NSArray
    保存此plist:

    @property (strong, nonatomic) NSArray *imagesList;
    
    并在
    viewdiload
    中进行加载(假设名为“ImagesList”的plist):

    剩下的是一些简单的
    UITableViewDatasource

    #pragma mark - UITableViewDatasource
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.imagesList.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
    
        if(!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"myCell"];
        }
    
        NSDictionary *eachImage = [self.imagesList objectAtIndex:indexPath.row];
    
        cell.textLabel.text = [eachImage objectForKey:@"date"];
        cell.detailTextLabel.text = [eachImage objectForKey:@"additionalDetail"];
    
        cell.imageView.image = [UIImage imageNamed:[eachImage objectForKey:@"imageName"]];
    
        return cell;
    }
    

    别忘了将图像放入应用程序包并正确重命名。

    如果您希望有人帮助您,则必须添加代码。我还没有编写任何代码。因此,你在问什么?1)让图像显示在单元格内-我将所有图像添加到Supporting Files文件夹中,并尝试将文件名输入plist,但plist不接受*如何显示plist支持文件中的图像?2) 添加用户单击单元格并从plist数据查看更多信息的功能*我需要什么代码才能用plist中的数据显示这个新视图?如果这里的人看到你已经尝试了一些努力,他们会更愿意提供帮助。否则,它将看起来像是一个家庭作业,有人正试图找到一个解决方案,几乎不费吹灰之力。尝试先做一些事情,然后在遇到问题时返回(粘贴代码、突出显示不起作用的位置等)。当我将self.imagesList更改为我的plist的名称时,它表示在View Controller类型的对象上找不到属性[plistName]?另外,UITableViewDataSource代码位于哪个文件下?您是否创建了plist文件?UITableViewDataSource位于管理表视图的控制器中;那么您的意思是UITableViewDataSource在.h视图控制器或.m视图控制器文件中?
    #pragma mark - UITableViewDatasource
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.imagesList.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
    
        if(!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"myCell"];
        }
    
        NSDictionary *eachImage = [self.imagesList objectAtIndex:indexPath.row];
    
        cell.textLabel.text = [eachImage objectForKey:@"date"];
        cell.detailTextLabel.text = [eachImage objectForKey:@"additionalDetail"];
    
        cell.imageView.image = [UIImage imageNamed:[eachImage objectForKey:@"imageName"]];
    
        return cell;
    }