ios - 通过 plist 的 TableView 部分

标签 ios objective-c uitableview plist

创建一个 plist 来存储单词及其定义的最佳方法是什么,然后用于填充按字母顺序分成多个部分的 TableView ,每个单元格通向一个详细 View 。 我连接了我的表和 plist,并了解如何通过准备 segue 获得详细 View 。我的问题是 plist 布局,然后将其用于章节标题并让单词与正确的字母相对应。

最近两天在 google 上多次搜索超过 30 页。我看过谓词之类的术语,但我很困惑。

我不希望有人编写代码,但步骤列表将是救命稻草。我担心不对表格进行分区会导致糟糕的使用体验。

最佳答案

只需按照下面的操作即可。

1.创建PList并赋予相关名称

2.做以下事情

   Key     Type         Value

   Root    Array        (2 items)

 ->Expend the arrow of root (to below-down) direction

   Item 0    Dictionary   (2 items)

 ->Expend the arrow of Item 0 (to below-down) direction->Click + and add the below things

   Name      String       First Section Name

   List      Array        (1 items)

 ->Expend the arrow of List (to below-down) direction->Just Click + for adding item 0

   Item 0     Dictionary   (6 items)

 ->Expend the arrow of  Item 0  (to below-down) direction ->Click + and the below things

   Name      String      EnterName

   Value     String     

   Key       String      Name

  UIType     String     TextField

  InputType  String      Text

  Mandatory   Boolean    YES

 Then  if you click the root there is +.Just click the + and you can see the Item 1

   Key     Type           Value

   Root    Array          (2 items)

  Item 0    Dictionary    (2 items)

  Item 1    Dictionary    (2 items)

  ->Expend the arrow of root (to below-down) direction

   Item 1    Dictionary   (2 items)

 ->Expend the arrow of Item 1 (to below-down) direction-Click + and add the below things

   Name      String       Second Section Name

   List      Array        (1 items)

 ->Expend the arrow of List (to below-down) direction-Just Click + for adding item 0

   Item 0     Dictionary   (6 items)

 ->Expend the arrow of  Item 0  (to below-down) direction-Click + and the below things

   Name      String      Enter Age

   Value     String     

   Key       String      Age

  UIType     String     TextField

  InputType  String      Text

  Mandatory   Boolean    YES

3.然后创建NSObject类名作为PList。

在 .h 中

  #import <Foundation/Foundation.h>

  @interface PList : NSObject

  + (NSMutableArray *)arrayPlistInit:(NSString *)plistName;

 @end

.m

  +(NSMutableArray *)arrayPlistInit:(NSString *)plistName

  {

    NSString *stringPath = [[NSBundle mainBundle]pathForResource:plistName ofType:@"plist"];

    NSMutableArray *arrayPlist = [NSMutableArray arrayWithContentsOfFile:stringPath];

    return arrayPlist;

  }

4.在viewDidLoad中

  arrayTable = [PList arrayPlistInit:stringPlistName];

5.然后查看ForHeaderInSection

 1.Create the Custom Label and View(see the below the Coding in viewForHeaderInSection)

            UILabel *labelSection;

            UIView  *viewSection = [[UIView alloc]init];

            viewSection.frame = CGRectMake(0, 0, tableviewCreate.frame.size.width, 20);

            labelSection = [[UILabel alloc]init];

            labelSection.textAlignment = NSTextAlignmentLeft;

            labelSection.frame = CGRectMake(10, 5, tableviewCreate.frame.size.width, 20);

            [labelSection setBackgroundColor:[UIColor clearColor]];

            [labelSection setFont:[UIFont boldSystemFontOfSize:15]];

            NSString *name = [[arrayTable objectAtIndex:section] objectForKey:@"Name"];

            labelSection.text = name;

关于ios - 通过 plist 的 TableView 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26642429/

相关文章:

objective-c - 类未被读取...未知类型名称

ios - 不兼容的整数到指针的转换将 'NSInteger'(又名 'int')发送到类型为 'NSInteger *'(又名 'int *')的参数

ios - 从 Firebase 数据库读取数据时出现问题

objective-c - 使用 LLVM GCC 4.2 不会让我将 CFStringRef 桥接到 NSString

iphone - 继承 UIViewController 类和 XIB

ios - 在 CitrusPay 网关 swift ios 中设置卡类型的问题

ios - 为什么 NSMutableDictionary 丢失数据?

ios - 如何从 UITableView 滑动触发 segue 以快速编辑

ios - 调整 UITableView 背景 View 的框架?

iphone - 检索在 sqlite 数据库中插入的所有行,并在包含标签的 TableView 单元格中显示为具有不同部分的 subview