2012-07-16 1 views
2

인기 섹션으로 UITableViewCellNSArray? 이벤트 배열이 있으며 cellForRowAtIndexPath에 데이터를로드하십시오. 연도 별 이벤트를 만들어야합니다.
예 :

섹션 2012
날짜 : 01/01/2012
이벤트 : 라이브 음악

날짜 : 2012년 1월 2일
이벤트 : 라이브 음악

section 2011
날짜 : 01/01/2011
이벤트 : 라이브 뮤직

날짜 : 2011년 1월 2일
이벤트 :
세포가 이미 채워진
단일 NSArray를 사용하여 UITbleViewCell에서 섹션을 만드는 방법은 무엇입니까?

, 나는 부분으로 만 분할을 그리워 라이브 뮤직, 섹션이 두 개 (최대 2 년)을 만듭니다.

죄송 합니다만, 아직 해결되지 않을 수 있습니다. 시험을 치르시겠습니까? 제발 도와주세요.

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

을 또한 당신이 가지고 : 나는 cell.textlabel.text이

시도 감사에게, 많은

-(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"; 
      } 
     } 
+0

년을 키로하여 사전에서 배열을 변형하는 방법에 대해 설명합니다. 키의 수는 테이블의 섹션 수와 요소의 수입니다. 각 키는 각 섹션의 행 수입니다 ... –

답변

0

을 내 코드를 게시합니다 HightForRow을 넓은 공간으로 설정하십시오.

등등

+0

답변을 주셔서 감사합니다. 지금은 프로젝트에 액세스 할 수 없습니다. 오늘 밤 느낍니다. We update – MarkGuitarHero

0

글쎄, 배열의 어느 부분이 끝나고 다른 부분이 시작되는지 알아 내야 할 것입니다. 두 개의 섹션이있는 경우 임 플러먼트

numberOfSectionsInTableView: 

및 반환 할 섹션 수 또는 몇 개의 섹션이있을 수 있습니다.

그런 다음 cellForRowAtIndexPath을 적절하게 변경하십시오. 섹션별로 구별해야합니다. 두 번째 섹션의 첫 번째 행 (행 0, 섹션 1)은 이전 섹션의 마지막 섹션을 벗어나는 배열의 첫 번째 객체와 일치해야합니다. (정도)

따라서 numberOfRowsInSection:을 변경해야합니다. 당신의 예제에서는 두 번 호출됩니다. 섹션 0에 대해 한 번, 섹션 1에 대해 한 번. 해당 섹션의 행 수를 반환합니다.

titleForHeaderInSection:을 구현하면 각 섹션의 틸트를 다시 구현할 수 있습니다.

당신은 UITableViewDataSource 프로토콜 참조에서 문서를 찾을 수

, http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDataSource

당신이 섹션 헤더의 가난한 레이아웃 기능을 극복하고 싶은 경우에, 당신은보기를 retuns 테이블 뷰 컨트롤러의 viewForHeaderInSection:는, 헤더로 표시 할 수 구현할 수 있습니다 각 섹션에 대해 이것은 UITableViewDelegate Protocol Reference에 문서화되어 있습니다. http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:viewForFooterInSection :

+0

답변을 주셔서 감사합니다. 지금은 프로젝트에 액세스 할 수 없습니다. 오늘 밤 느낍니다. 업데이트 – MarkGuitarHero

관련 문제