数组与字典的应用

来源:互联网 发布:在线打电话软件 编辑:程序博客网 时间:2024/06/08 03:32

一组数据有图片及文字描述

 

//  设置数组属性
@interface
@property (nonatomic, strong) NSArray *imageData;
@property (nonatomic, assign) int index;
@end


@implementation     //   创建包含 图片名称及描述 的字典    NSMutableDictionary *imageWithDesc1 = [NSMutableDictionary dictionary]; 
    imageWithDesc1[@"icon"] = @"图片名称1";    imageWithDesc1[@"desc"] = @"图片描述1";    NSMutableDictionary *imageWithDesc2 = [NSMutableDictionary dictionary];    imageWithDesc2[@"icon"] = @"图片名称2";    imageWithDesc2[@"desc"] = @"图片描述2";    NSMutableDictionary *imageWithDesc3 = [NSMutableDictionary dictionary];    imageWithDesc3[@"icon"] = @"图片名称3";    imageWithDesc3[@"desc"] = @"图片描述3";
<pre name="code" class="objc"><span style="white-space:pre"></span>
    //  创建数组
    self.imageData = @[imageWithDesc1, imageWithDesc2, imageWithDesc3];
   <pre name="code" class="objc">    //  提出数组里index对应的字典数据
    NSArray *imageDict = imageData[self.index];
    <pre name="code" class="objc">    //  设置图片名称
    NSString *iconName = imageDict[@"icon"];
    //  设置图片描述
    NSString *iconDesc = imageDict[@"desc"];
</pre><pre name="code" class="objc"><span style="font-family: Arial, Helvetica, sans-serif;">@end</span>





0 0
原创粉丝点击