2

UITableViewCell単品での人気コーナーとしてはNSArray?イベントの配列があり、データを にロードしますcellForRowAtIndexPath。年イベントごとにセクションを作成する必要があります。
例:

section 2012
Date: 01/01/2012
Event: Live Music

Date: 01/02/2012
Event: Live Music

section 2011
Date: 01/01/2011
Event: Live Music

Date: 01/02/2011
Event: Live Music

セルには既に値が設定されています。セクションへの分割、2 つ (最大 2 年) を作成するセクションだけが欠けています。

申し訳ありませんが、まだ少し混乱しています。解決できません。助けてください。今年のテストはいつですか?コードを投稿します、どうもありがとう

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
              //acquisisco la data dell'evento
        NSString *dataEv = [[events objectAtIndex:indexPath.row + indexPath.section]DataEvento];


//retrive year ,example 2011, 2012 when test?
NSString *Year = [Utility getPartOfDate:dataEv type:UTLGetYear];
    //set image
    ...
    [cell.contentView addSubview:myImg];

    //set day
    day.text = [Utility getPartOfDate:dataEv type:UTLGetNumberOfDay];;
    [cell.contentView addSubview:day];

    //set dayOfWeek
    ...
    dayOfWeek.text = [Utility getPartOfDate:dataEv type:UTLGetDayOfWeek];;
    [cell.contentView addSubview:dayOfWeek];

    //set month
    month.text = [Utility getPartOfDate:dataEv type:UTLGetTextMonth];;
    [cell.contentView addSubview:month];

    //set title
    ...
    lblTitleEvent.text = [[eventi objectAtIndex:indexPath.row + indexPath.section]Artist];
    [cell.contentView addSubview:lblTitoloEvento];

    //set description event
    lblDescEvento.text = [[eventi objectAtIndex:indexPath.row + indexPath.section]Description];
    [cell.contentView addSubview:lblDescriptionEvent];


      }else{

    lblTitleEvent = (UILabel*)[cell.contentView viewWithTag:5];
    lblTitleEvent.text = [[events objectAtIndex:indexPath.row + indexPath.section]Artista];

    lblDescEvent = (UILabel*)[cell.contentView viewWithTag:6];
    lblDescEvent.text = [[events objectAtIndex:indexPath.row + indexPath.section]Description];
}

return cell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}


    // Customize the number of rows in the table view.
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       return [events count];        
    }

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {        
            if(section == 0){
                return @"Section 1";
            }
            if(section == 1){
                return @"Section 2";
            }
        }
4

2 に答える 2

0

これを試して

cell.textlabel.text で:

cell.textlabel.text = [NSString stringWithFormat:@"%@/n%@/n%@",[array1 ObjectAtIndex:row],......];

HightForRowまた、より広いスペースに設定する必要があります

等々

于 2012-07-16T09:23:33.387 に答える
0

さて、配列のどこで 1 つのセクションが終わり、もう 1 つのセクションが始まるかを見つける必要があります。2 つのセクションがある場合は、実装

numberOfSectionsInTableView:

2 またはいくつのセクションがあるかを返します。

次に、cellForRowAtIndexPathそれに応じて変更します。セクションごとに区別する必要があります。2 番目のセクションの最初の行 (行 0、セクション 1) は、前のセクションの最後のオブジェクトを超える、配列内の最初のオブジェクトに対応する必要があります。(とか、ぐらい)

それに応じて変更する必要がありますnumberOfRowsInSection:。あなたの例では、2回呼び出されます。セクション 0 に 1 回、セクション 1 に 1 回。そのセクションの行数を返します。

titleForHeaderInSection:ヘッダーについては、各セクションのチルトを返す実装を実装できます。

ドキュメントは UITableViewDataSource プロトコル リファレンス ( http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDataSource ) にあります。

セクション ヘッダーの貧弱なレイアウト機能を克服したい場合はviewForHeaderInSection:、各セクションのヘッダーとして表示されるビューを返すテーブル ビュー コントローラーの を実装できます。UITableViewDelegate プロトコル リファレンス、http: //developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:viewForFooterInSection に記載されています。 :

于 2012-07-16T09:26:13.607 に答える