0

検索ビューを持つアプリケーションで作業している場合、検索ビューには3つのセクションを持つtableViewが含まれます-セクションを手動で実装します

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    // Return the number of sections.
    return 3;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    if (section == 0){
        UITextField *title = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 320, 10)];
        [title setBackgroundColor:[UIColor lightGrayColor]];
        [title setTextAlignment:UITextAlignmentRight];
        [title setFont:[UIFont boldSystemFontOfSize:15]];
        [title setText:@"videos"];
        return title ;
    }
    if (section == 1){
        UITextField *title = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 320, 10)];
        [title setBackgroundColor:[UIColor lightGrayColor]];
        [title setTextAlignment:UITextAlignmentRight];
        [title setFont:[UIFont boldSystemFontOfSize:15]];
        [title setText:@"documents"];
        return title ; 
    }
    if (section == 2){
        UITextField *title = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 320, 10)];
        [title setBackgroundColor:[UIColor lightGrayColor]];
        [title setTextAlignment:UITextAlignmentRight];
        [title setFont:[UIFont boldSystemFontOfSize:15]];
        [title setText:@"questions"];
        return title ; 
    }
}

これで、次のようなXMLで受信したすべてのデータが次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"> 
<channel>
    <title>documents</title>
        <item>
        <title>how to count the days</title>
        <link>some link...</link>
        <date>11/09/2007 16:45:00</date>
        <SupplierName>roei</SupplierName>
        <CategoryName>the omer</CategoryName>

      </item>

        <item>
        <title>research</title>
        <link>some link...</link>
        <date>16/05/2010 13:41:00</date>
        <SupplierName>eran</SupplierName>
        <CategoryName>shavoot</CategoryName>
      </item>

</channel>

<channel>
    <title> video </title>
                <item>
                <title>the end of holiday</title>
                <link>some link...</link>
                <date>06/06/2011 08:56:00</date>
                <SupplierName>dina</SupplierName>
                <CategoryName>shavoot</CategoryName>

              </item>

                <item>
                <title>bible</title>
                <link>some link...</link>
                <date>24/05/2012 10:00:00</date>
                <SupplierName>amir</SupplierName>
                <CategoryName>shavoot</CategoryName>        
              </item>

</channel>



        <channel>
            <title>questions</title>

                <item>
                <title>questions for shavvot</title>
                <link>some link...</link>
                <date>28/10/2008 13:31:00</date>
                <SenderName>אלי.ד.</SenderName>
                <CategoryName>holidays</CategoryName>
              </item>

                <item>
                <title>Shavoot</title>
                <link>some link...</link>
                <date>25/05/2008 01:01:00</date>
                <SenderName>amir</SenderName>
                <CategoryName>holidays</CategoryName>
              </item>


        </channel>


</rss>

ご覧のとおり、セクションの名前が付いたタイトルがありますが、セルの正しいセクションをどのように決定する必要がありますか?すべてのデータを1つの配列に解析し、辞書を使用して取得します。

NSDictionary *object = [ResultsArrayDisplay objectAtIndex:indexPath.row];

私を助けてください、これまでのところインターネットで何も役に立たなかった数時間の試行の後のim。

4

1 に答える 1

0

これがあなたの問題です:

すべてのデータを1つの配列に解析し、辞書を使用して取得します。

各セクションのデータを独自の配列に配置し、を使用indexPath.sectionして使用する配列を決定します。セクションごとに、そのセクションの行のみが表示されるため、を使用しindexPath.rowて各配列にインデックスを付けることができます。

すべてを1つの配列に保持することを主張する場合は、各タイプの数を維持し、それを使用して必要な配列インデックスを把握する必要があります。

いずれの場合も、必ずを実装してnumberOfRowsinSection:ください。複数のアレイを使用している場合、これはそのセクションのアレイカウントになります。それ以外の場合は、そのセクションで使用されるメインアレイの部分になります。

于 2012-05-29T17:21:22.610 に答える