2013-07-29 3 views
1

셀 스타일 변경에 대한 질문. 콘텐츠 : 동적 원형섹션에 대한 uiTableview 셀 스타일 변경

코드

섹션 번호 : 하나의 스토리 보드로 생성 한 레이아웃을 사용할 수있는 2

제 은 스토리 보드, I는 셀을 만들었다. 셀은 데이터베이스의 데이터로 완벽하게 채 웁니다. 섹션 2의 셀 레이아웃을 value1 스타일로 변경하려고합니다.

어떻게이 작업을 수행 할 수 있습니까?

코드의 일부 : 당신은 셀의 셀 스타일을 설정해야

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"cartCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    switch (indexPath.section) { 

     case 0: 
     {  
      // Configure the cell... 
      NSInteger row = [indexPath row]; 
      [[cell textLabel] setText:[cartItems objectAtIndex:row]]; 

      return cell; 
      break; 
     } 

     case 1: 
     { 


      NSInteger row = [indexPath row]; 
      switch (row) { 
       case 0: 
        [[cell textLabel] setText:@"Total1"]; 
        break; 
       case 1: 
        [[cell textLabel] setText:@"Total2"]; 
      } 

      return cell; 
      break; 
     } 
    } 
} 
+0

당신이 우리의 대답을 시도하고 당신이 최대 무엇에 대한 피드백을 제공한다 : 그리고 cellForRowAtIndexPath에, 단지 스위치 문 또는 절 다른-경우 내부에 원하는 식별자가 셀을 큐에서. –

+0

답변을 살펴 봅니다. 나에게 시간을 좀주세요. 이것은 부업입니다. – TomVD

답변

2

이렇게하는 방법은 각각 고유 한 식별자가있는 스토리 보드에 2 개의 다른 동적 프로토 타입을 만드는 것입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (indexPath.section == 0) { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
     cell.textLabel.text = self.theData[indexPath.section][indexPath.row]; 
     return cell; 

    }else{ 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell_value1" forIndexPath:indexPath]; 
     cell.textLabel.text = self.theData[indexPath.section][indexPath.row]; 
     cell.detailTextLabel.text = @"detail"; 
     return cell; 

    } 
} 
+0

스토리 보드에 여러 프로토 타입을 만드는 것이 트릭을 만들었습니다. 여러개를 만들 수 있다는 것을 몰랐습니다. – TomVD

0

을 그들과 함께 플레이하고 원하는 결과를 얻으려면

There are four inbuilt styles supported in iOS 
    1. UITableViewCellStyleDefault 
    2. UITableViewCellStyleValue1 
    3. UITableViewCellStyleValue2 
    4. UITableViewCellStyleSubtitle 

시도 코드 아래에보십시오

정적 NSString * reuseIdentifer = @ "ReuseIdentifier";

// Try to reuse the cell from table view 
     UITableViewCell *cell = 
     [tableView dequeueReusableCellWithIdentifier:reuseIdentifer]; 

     // If there are no reusable cells; create new one 
     if (cell == nil) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 


             reuseIdentifier:reuseIdentifer]; 
      } 
cell.textLabel.tex = @"Your desired text"; 
return cell; 
관련 문제