gpt4 book ai didi

objective-c - 如何在细节 Controller 中引用属性列表?

转载 作者:行者123 更新时间:2023-11-28 17:43:34 24 4
gpt4 key购买 nike

我正在构建一个向下钻取应用程序,其中的选项卡栏充当 rootViewController。除了详细 View 外,该应用程序功能齐全。我在 .plist 中概述了三个属性:标题、关联图像和行业信息。

所以我在我的头文件中创建了这些变量:

@interface DetailView : UIViewController {

NSDictionary *industryData;

IBOutlet UILabel *titleLabel;
IBOutlet UIImageView *associatedImage;
IBOutlet UITextView *industryInfo;

}

@property (nonatomic, retain) NSDictionary *industryData;

@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UIImageView *associatedImage;
@property (nonatomic, retain) IBOutlet UITextView *industryInfo;

@end

我确定我能够正确使用 viewDidLoad 方法的第二部分,但我无法将其与我的 .plist 相关联。不过,我对第一部分仍然感到困惑:

{
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"IndustryData.plist"];

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.industryData = tempDict;
[tempDict release];

associatedImage.image = [UIImage imageNamed:[industryData valueForKey:@"Associated Image"]];
titleLabel.text = [industryData valueForKey:@"Title"];
industryInfo.text = [industryData valueForKey:@"Industry Info"];

[super viewDidLoad];
}

我想我的问题源于前五行代码。我试图将我对导航部分所做的应用到详细 View ,但是当它加载时屏幕上没有内容。如何让我的详细信息与我的原始 .plist 相关联?

编辑:

我认为这是值得添加的,来 self 的“IndustryView”,也就是导航的 View Controller :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];

//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];

Dg3_z_Z4_8AppDelegate *AppDelegate = (Dg3_z_Z4_8AppDelegate *) [[UIApplication sharedApplication] delegate];

if([Children count] == 0) {

DetailView *dvController = [[DetailView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];

[AppDelegate.indNavControl pushViewController:dvController animated:YES];

[dvController release];
}

还有一个 else 部分,但它在这里不是特别相关。谢谢!

最佳答案

尝试

[[NSBundle mainBundle pathForResource:@"IndustryData" ofType:@"plist"]

或者,将细节项作为细节 View Controller 的属性,并在推送之前设置它们。

关于objective-c - 如何在细节 Controller 中引用属性列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7098627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com