2013-05-07 3 views
0

UITableView를로드하는 메뉴 스타일로 슬라이드를 사용하고 있습니다.현재 항목을 표시하는 UITableView 메뉴 설정

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

cell.contentView.backgroundColor = [UIColor colorWithRed:75.0/255.0 green:83.0/255.0 blue:102.0/255.0 alpha:1.0]; 

UIView *topSplitterBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.bounds.size.width, 1)]; 
topSplitterBar.backgroundColor = [UIColor colorWithRed:62.0/255.0 green:69.0/255.0 blue:85.0/255.0 alpha:1]; 

[cell.contentView addSubview:topSplitterBar]; 

cell.textLabel.backgroundColor = [UIColor clearColor]; 
cell.textLabel.textColor = [UIColor colorWithRed:196.0/255.0 green:204.0/255.0 blue:218.0/255.0 alpha:1]; 
cell.textLabel.font = [UIFont systemFontOfSize:18.0f]; 
cell.textLabel.shadowColor = [UIColor colorWithRed:27.0/255.0 green:31.0/255.0 blue:41.0/255.0 alpha:1]; 
cell.textLabel.shadowOffset = CGSizeMake(0, 1); 

UIView *selectedBg = [[UIView alloc] initWithFrame:cell.frame]; 
selectedBg.backgroundColor = [UIColor colorWithRed:50.0/255.0 green:56.0/255.0 blue:73.0/255.0 alpha:1]; 
cell.selectedBackgroundView = selectedBg; 

것은 무슨는 현재 표시 컨트롤러 인 경우 selectedBg로 셀을 보여줄 수있는 가장 좋은 방법이 될 것입니다 : - 다음과 같이 ECSlidingViewController

나는 테이블보기 설정에서 약 7 세포가?

나는 예를 들어 다음에 액세스 할 수 있습니다 그러나

if ([self.slidingViewController.topViewController isKindOfClass:[MESHomeViewController class]]) { 

을 나는 곳을 설정하는 가장 좋은 방법이 될 것입니다 확실하지 않다? 내가 예를 들어 ... 셀 라벨 설정을위한 스위치의 경우에 그것을 할 수 있습니다 : 새 항목이 메뉴를 선택하면

switch (indexPath.row) { 
     case 0: { 
      if ([self.slidingViewController.topViewController isKindOfClass:[MESHomeViewController class]]) { 
       cell.contentView.backgroundColor = [UIColor colorWithRed:50.0/255.0 green:56.0/255.0 blue:73.0/255.0 alpha:1]; 
      } 
      cell.textLabel.text = NSLocalizedString(@"LMGames", @"Left Menu - Games"); 
      break ; 

그러나, 나는 테이블마다 다시로드해야 좋은 것입니다 ? 셀이 선택 될 때마다 self.tableView reloadData을 완료하거나 더 좋은 방법이 있습니까? 당신을 위해

+0

또는'didSelectRowAtIndexPath' 메소드에서'selectedBg'도 설정하십시오. – iwasrobbed

+0

이 'UITableViewCell * cell = [tableView cellForRowAtIndexPath : indexPath];를 추가하려고했습니다. cell.contentView.backgroundColor = [UIColor colorWithRed : 50.0/255.0 녹색 : 56.0/255.0 파랑 : 73.0/255.0 알파 : 1]; 'didSelectRowAtIndexPath 부분에 있지만 변경 사항이 발생하지 않습니다? – StuartM

+0

@iWasRobbed - 알았어, BOOL이 사용 중이지만 자체 tableView reloadData에서만 작동합니다. 이것은 셀이 현재 표시되어있는 경우 셀 생성을 체크 인합니다 (그와 같이). 문제는 이것을 달성하는 가장 좋은 방법인가? didSelectRowAtIndexPath의 표시를 변경하면 다른 셀 배경이 올바른지 확인하는 방법 ... tableView의 데이터를 다시로드하지 않고 확인하십시오. – StuartM

답변

1

두 아이디어 :

  1. 선택한 셀을 설정하기 위해 didSelectRowAtIndexPath 방법에 selectedBg을 설정합니다.
  2. 현재 선택한 행의 정수 참조 및 이전에 선택한 행을 유지하고 다음과 같은 방법을 사용하여 행만을 새로 고침 : How to reload and animate just one UITableView cell/row?

내가 희망이 도움이!

+0

다시 한번 감사드립니다. – StuartM

관련 문제