1

私はあらゆる種類のデバイスのプログラミングにかなり慣れておらず、急な学習曲線を描いているので、これがあまり意味をなさない場合や問題のコードがひどい場合はご容赦ください。私たちは皆、どこかから始めなければなりません。読んで読んで読んだ!

辞書の配列であるplistからテーブルを作成しています-後で値の一部を変更して関連するplist 'key'に書き戻すことができるようにしたいので、この形式で必要です。誰かがこれを見て、どうすればよいかについての指針を教えてくれることを願っています...

  1. plist のキー/値 'name' の下にあるデータをグループ化されたスタイルで A から Z に並べ替えるテーブルを作成します。辞書の一部は同じセクションの下にグループ化する必要がありますが、plist の配列 (以下を参照)
  2. plist の項目に従ってテーブルをセクションに分割します。アルファベットにまたがる7つのアイテムがある場合、7つのセクションが必要です。
  3. 関連する数のエントリのみを含むインデックスを右側に配置します。「Q」の下にデータがない場合は、「Q」をインデックスに表示したくありません。

明らかに、私はこれをすべて整理するには長い道のりです.コード自体は、現時点では「犬の夕食」のようなものです.私にお知らせください!

UILocalizedIndexedCollat​​ion や sortedArrayUsingDescriptors など、関連するすべてのセクションを読み込もうとしていますが、私の脳はそれに対応していないと思います...

ありとあらゆるアドバイス(私が始めたことを決してあきらめないので、「あなたはこれを行うには十分な明るさ​​ではないのであきらめてください!」を除く)は大歓迎です!

(最初に合成された未使用の変数がたくさんあります-ここに投稿したものを簡素化するために関連するコードを取り出しました。コードは問題なくコンパイルされ、次の結果が得られました:27文字のインデックス付きのテーブル右側では、AJ のみが機能します (これは、テーブルで生成されるセクションの数に相関します - セクション AJ のみがあります。セルの内容はまさに私が望むものです。)

#import "RootViewController.h"

#import "View2Controller.h"
#import "tableviewsAppDelegate.h"
#import "SecondViewController.h"
#import "HardwareRootViewController.h"
#import "HardwareSecondViewController.h"
#import "SoftwareRootViewController.h"

@implementation SoftwareRootViewController

@synthesize dataList2;
@synthesize names;
@synthesize keys;
@synthesize tempImageType;
@synthesize tempImageName;
@synthesize finalImageName;
@synthesize tempSubtitle;
@synthesize finalSubtitleName;
@synthesize tempSubtitleType;
@synthesize finalSubtitleText;
@synthesize sortedArray;
@synthesize cellName;
@synthesize rowName;

//Creates grouped tableview//
- (id)initWithStyle:(UITableViewStyle)style {
     if (self = [super initWithStyle:UITableViewStyleGrouped]) {
     }
     return self;
}

- (void)viewDidLoad {
     //loads in backgroundimage and creates page title//
     NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"background1" ofType:@"png"];
     UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundPath];
     UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage];
     self.tableView.backgroundColor = backgroundColor; 
     [backgroundColor release];     
     self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.5 green:.4 blue:.3 alpha:5];
     self.title = @"Software";

    [super viewDidLoad];

     //Defines path for DATA For ARRAY//
     NSString *path = [[NSBundle mainBundle] pathForResource:@"DataDetail3" ofType:@"plist"]; 

     //initialises the contents of the ARRAY with the PLIST//     
     NSMutableArray* nameArray = [[NSMutableArray alloc] 
                              initWithContentsOfFile:path]; 

//Sorts the items in the list alphabetically//

     NSSortDescriptor *nameSorter = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
     [nameArray sortUsingDescriptors:[NSArray arrayWithObject:nameSorter]];
     [nameSorter release];

     self.dataList2 = nameArray; 
     [nameArray release];
}

- (void)didReceiveMemoryWarning {
     // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
     // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
     // Release anything that can be recreated in viewDidLoad or on demand.
     // e.g. self.myOutlet = nil;
}


#pragma mark Table view methods
// Customize the appearance of table view cells.

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
          static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                                         SectionsTableIdentifier ];
          if (cell == nil) {
                    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                                     reuseIdentifier: SectionsTableIdentifier ] autorelease];
          }

// Configure the cell.
          cell.indentationLevel = 1;
          cell.textLabel.text = [[self.dataList2 objectAtIndex:indexPath.row] 
                                      objectForKey:@"name"]; 
          cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

//Detremines the cell color according to the value in 'owned' in the plist//
          NSString *textColor = [[self.dataList2 objectAtIndex:indexPath.row] 
                                      objectForKey:@"owned"];

     if ([textColor isEqualToString: @"greenColor"]) {
               [cell setBackgroundColor:[UIColor colorWithRed:0.1 green:0.7 blue:0.1 alpha:1]];
          }
               if ([textColor isEqualToString: @"blackColor"]) {
                    [cell setBackgroundColor:[UIColor whiteColor]];
          }
          return cell;
     }



// Code For Loading of The View2Controller//


- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
          NSString *CellIdentifier = [[self.dataList2 objectAtIndex:indexPath.row] 
                                        objectForKey:@"name"];
     NSString *rowTitle = CellIdentifier;
     NSLog(@"rowTitle = %@", rowTitle);
     [tableView deselectRowAtIndexPath:indexPath animated:YES];

          SecondViewController *second = [[SecondViewController alloc] init];
          [second setCategory: rowTitle];
          [self.navigationController pushViewController:second animated:YES];
          [second release];
}     

- (void)dealloc {
     [dataList2 release];
    [super dealloc];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return [dataList2 count];
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return [dataList2 count];  ///Tells the table that it only needs the amount of cells listed in the DATALIST1 ARRAY//

}//
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)help
{
     return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex:help];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
     return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
     return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index];
}     



@end

アドバイスをいただければ幸いです - 現在、私はこれに約 1 週間取り組んでいますが、成功していません。

最悪の事態が来て、私がこれを成し遂げることができない場合、誰かが私のために機能を書いてくれます。

乾杯、そしてここに願っています...

チャブス

4

1 に答える 1

1

UILocalizedIndexCollat​​ion を使用 =]

于 2010-12-07T19:47:37.950 に答える