0

我试图让我的 plist 库中每个项目的标签和图像显示在我的详细信息选项卡中。

这是我的 tableview 的图片,我可以让我的 plist 字典工作。一组图像和一个或多个项目。(例如第 0 项是 thermostat.jpg 和 Thermostat 标签。

在此处输入图像描述

这是单击单元格时详细视图的图片。它从单元格中提取标签和恒温器的图像。

在此处输入图像描述

但是,当单击 plist(厕所)中的第 1 项时,它会拉出厕所名称,但仍会显示恒温器图像。像这样。

在此处输入图像描述

这是我的 detailviewcontroller 代码

.h

#import <Foundation/Foundation.h>

@interface DetailViewController : UIViewController
{
IBOutlet UIScrollView *scrollView;

}

@property (nonatomic, strong) IBOutlet UILabel *itemLabel;//Name of that view
@property (nonatomic, strong) NSString *itemName;

@property (nonatomic, strong) IBOutlet UIImageView *myImageView; //Image View
@property (strong, nonatomic) IBOutlet UILabel *myTextView; //Description View

@end

和.m

#import "DetailViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController

@synthesize itemLabel;
@synthesize itemName;
@synthesize myImageView;
@synthesize myTextView;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.


itemLabel.text = itemName;
//**************SCROLL VIEW*************
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320,960)];
scrollView.contentInset=UIEdgeInsetsMake(0.0,0.0,90.0,0.0);


////I know below this is the Problem, BUT im not sure what its supposed to be?////
NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle     mainBundle] pathForResource:@"repairlist" ofType:@"plist"]];
NSArray *imageArray = [picturesDictionary objectForKey:@"Thumbnail"];
myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:0]];

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

所以总而言之,我试图让图像在单击该单元格时正确显示

这是我使用的 plist 的图像:

在此处输入图像描述

我的 TableViewController 中已经有了这个

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ItemListCell"]) {
    DetailViewController *destViewController = segue.destinationViewController;

    NSIndexPath *indexPath = nil;

    if ([self.searchDisplayController isActive]) {
        indexPath = [self.searchDisplayController.searchResultsTableView     indexPathForSelectedRow];
        destViewController.itemName = [searchResults objectAtIndex:indexPath.row];


    } else {
        indexPath = [self.myTableView indexPathForSelectedRow];
        destViewController.itemName = [repairList objectAtIndex:indexPath.row];
        //destViewController.textView = [descrip objectAtIndex:indexPath.row];
    }
  }

}
4

1 回答 1

0

这是你的问题,

myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:0]];

您将图像始终设置为相同的索引,即 0。因此,从逻辑上讲,您总是看到相同的图像。因此,您需要在推送DetailViewController并将该信息传递给您的DetailViewController. 然后,您需要使用该信息在您的DetailViewController.

首先,您需要在 中声明一个属性DetailViewController.h

@property int selectedRow;

也改变这行代码

myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:0]];

myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:self.selectedRow]];

然后在你的TableViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"YourSegueIdentifier"]) {
        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        DetailViewController *detailViewController = [segue destinationViewController];
        detailViewController.selectedRow = [dataController objectInListAtIndex:selectedRowIndex.row];
    }
}
于 2013-09-13T00:21:41.457 回答