1

テーブルビューで、連絡先の名前、会社名、連絡先の写真を表示する必要があります。

ここに画像の説明を入力してください

連絡先の追加/編集ページから連絡先を追加/編集できます。

ここに画像の説明を入力してください

追加/編集ページに値を入力すると、それらを辞書に保存します。

配列ContactsArrayでContactNamesを取得し、この配列を使用してセクションとヘッダーを設定しようとしました。

このプロセスでは、保存したものが他のフィールドに表示されません。didSelectRowメソッドでもこの問題が発生した場合でも、詳細なテキストラベルを確認してください。

いずれかのセクションの1行目を選択すると、1番目のセクションの1sr行の詳細ページに移動します。

いずれかのセクションの2行目を選択すると、1番目のセクションの2行目の詳細ページに移動します

セクションの問題かもしれません

//ViewDidLoadメソッドの内部

  sections = [[NSMutableDictionary alloc] init]; ///Global Object

  BOOL found;

  for (NSString *temp in contactsArray)
  {        
        NSString *c = [temp substringToIndex:1];

        found = NO;

        for (NSString *str in [sections allKeys])
        {
              if ([str isEqualToString:c])
              {
                    found = YES;
              }
        }

        if (!found)
        {     
              [sections setValue:[[NSMutableArray alloc] init] forKey:c];
        }
  }
  for (NSString *temp in contactsArray)
  {
        [[sections objectForKey:[temp substringToIndex:1]] addObject:temp];
  }

      [contactsTable reloadData];

}

テーブルビューメソッド

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


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
      return [[sections valueForKey:[[[sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:section]] count];
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      static NSString* CellIdentifier = @"Cell";
      UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if(cell == Nil)
      {
            cell  = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
      }
      NSString *titleText = [[sections valueForKey:[[[sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

       cell.textLabel.text = titleText;

      Contact *contact = [storedContactsArray objectAtIndex:indexPath.row];
      Contact *contactPicture = [storedPicsArray objectAtIndex:indexPath.row];


          _____________________________________

           cell.detailTextLabel.text = contact.companyName;
          UIImage *contactImage =  [[UIImage alloc]initWithContentsOfFile:contactPicture.contactImage];
           cell.imageView.image = contactImage;
            _______________________________
              return cell;
}

私がBbを宗派にしたときでさえ、それはAAAAAページの詳細にナビゲートします。

このリンク http://www.devx.com/wireless/Article/43374/0/page/2でも試してみましたが、同じ問題を繰り返しても

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      EditContact *editContact = [[EditContact alloc] init];
      if([self.storedContactsArray count] != 0)
      {
            Contact *contactsDict = [storedContactsArray objectAtIndex:indexPath.row];
            editContact.contactInfo = contactsDict;

            Contact *picsDict = [storedPicsArray objectAtIndex:indexPath.row];
            editContact.storedPicsDict = picsDict;
      }

      [self.navigationController pushViewController:editContact animated:YES];
      [editContact release];
      [storedContactsArray release];

}

ここに画像の説明を入力してください

4

2 に答える 2

0

複数のセクションにわたって行インデックスを使用することはできません。すべてのセクションindexPath.rowで、再び 0 から始まります。あなたも使っていますindexPath.section

私の意見では、これを解決するには2つの方法があります。

  1. コード全体をリファクタリングして、すべての開始文字含む辞書と、内部にすべての連絡先を含む配列を取得します
  2. すべての文字 (a、b など)sectionsについて、辞書のサブ配列に連絡先全体を保存します。これを行った場合は、次のようにandの代わりに使用できます。sectionsstoredContactsArraystoredPicsArrayNSDictionary *contactData = [[[sections objectForKey:[[sections allKeys] objectAtIndex:indexPath.section]] objectForKey:@"contacts"] objectAtIndex:indexPath.row];

また、さまざまなコード行を保存できます。

  for (NSString *temp in contactsArray)
  {        
        NSString *c = [temp substringToIndex:1];

        if ([sections objectForKey:c] == nil)
        {     
              [sections setValue:[[NSMutableArray alloc] init] forKey:c];
        }
  }

以下と同じです:

  for (NSString *temp in contactsArray)
  {        
        NSString *c = [temp substringToIndex:1];

        found = NO;

        for (NSString *str in [sections allKeys])
        {
              if ([str isEqualToString:c])
              {
                    found = YES;
              }
        }

        if (!found)
        {     
              [sections setValue:[[NSMutableArray alloc] init] forKey:c];
        }
  }
于 2012-11-01T07:44:10.617 に答える
0

tableView:didSelectRowAtIndexPath: delegate メソッドで何をしているのかわかりますか?

于 2012-11-01T07:26:21.627 に答える