2014-10-29 50 views
1

什麼是創建plist來存儲單詞及其定義,然後用於填充表格視圖按字母順序分成多個部分的最佳方式,每個單元格導致一個詳細視圖。 我有我的桌子和plist連接,並瞭解如何獲得細節視圖與準備segue。我的問題是plist佈局,然後使用它作爲部分標題,並獲得對應正確字母的單詞。通過plist的表格視圖部分

過去兩天已經在谷歌上多次搜索花費超過30頁。我看過像謂詞這樣的術語,但我很困惑。

我不希望有人編碼,但步驟列表將是一個救星。我擔心如果未能對錶格進行分段會導致糟糕的使用體驗。

+0

如果不知道你的plist現在是什麼樣子,很難給你提供建議。那麼,你的plist的結構是什麼? – rdelmar 2014-10-30 03:54:27

回答

0

這樣的模糊細節很難回答這個問題,但我會盡力的。尤其不知道你如何將這些單詞存儲在plist中。假設你只是將字符串存儲在plist中,那麼只需讀取整個文件,然後抓取所有單詞的第一個字母並將它們放入NSSet(一組是一個數據結構,它只允許任何數據出現一次)。有了這個,你將有你的索引,可用於創建部分。

然後將您的NSSet映射到字典。每個鍵將是該集合中的一個值,它們的值將包含以該字母開頭的單詞的數組。

我沒有實現這一點,但我會遵循這種方法。

1

只要按照下面這個。

1.創建plist中,並給予相關的名稱

2.Do以下的事情

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.Then創建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.in viewDidLoad中

arrayTable = [PList arrayPlistInit:stringPlistName]; 

5.Then viewForHeaderInSection

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;