2013-11-15 10 views
0

xcode5를 처음 사용합니다. 그리고 난 내 애플 리케이션에 tableview 그룹화하는 데 사용. iOS6.1에서는 정상적으로 작동하지만 iOS7에서는 데이터가 표시되지 않습니다. 그냥 "헤더"섹션을 표시합니다. 내 코드 즉 :xcode5의 그룹 테이블 뷰에 데이터를 표시 할 수 없습니다.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [atableView reloadData]; 

    self.notification = [[UISwitch alloc] initWithFrame:CGRectZero]; 
    LoginSetting = [[NSArray alloc] initWithObjects:@"Company ID",@"Username",nil]; 
    [LoginSetting retain]; 
    mic = [[NSArray alloc] initWithObjects:@"Notification",@"App Version",@"Server",nil]; 
    [mic retain]; 

    detailText=[[NSArray alloc]initWithObjects:@"kaisquare",@"admin",nil]; 
    [detailText retain]; 

    logout=[[NSArray alloc]initWithObjects:@"",nil]; 
    self.title = @"Setting"; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 3; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if(section == 0) 
     return [LoginSetting count]; 
    else if(section==1) 
     return [mic count]; 
    else 
     return [logout count]; 
} 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    if(section == 0) 
     return @"Login Setting"; 
    else if(section==1) 
     return @"Mics"; 
    else 
     return @""; 
} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.section == 0) 
    { 
     if (indexPath.row == 0) 
     { 

     } 
     else if (indexPath.row == 1) 
     { 

     } 
     else 
     { 

     } 
    } 
    else if(indexPath.section==1) 
    { 
     if (indexPath.row == 0) 
     { 

     } 
     else if (indexPath.row == 1) 
     { 
     } 
     else if (indexPath.row == 2) 
     { 

      alertView = [[UIAlertView alloc] initWithTitle:@"Server" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Okay", nil]; 
      alertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
      myTextField = [alertView textFieldAtIndex:0]; 
      myTextField.text=mainString; 
      [alertView show]; 
      [alertView release]; 
     } 
     else 
     { 

     } 
    } 
    else 
    { 
     if (indexPath.row == 0) 
     { 
     } 
    } 

} 
-(void)alertView:(UIAlertView *)alertView 
didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 

    if (buttonIndex != 1) 
    { 
     NSLog(@"Cancel"); 
     return; 
    } 
    else 
    { 

    } 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView 
           dequeueReusableCellWithIdentifier:CellIdentifier 
           forIndexPath:indexPath]; 
    if (cell == nil) 
    { 
     // cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault          reuseIdentifier:CellIdentifier]; 
     cell.backgroundColor = [UIColor clearColor]; 

     cellCompanyId = [[UILabel alloc] initWithFrame:CGRectMake(-20, 0, cell.frame.size.width, cell.frame.size.height)]; 
     cellCompanyId.backgroundColor = [UIColor clearColor]; 
     cellCompanyId.font = [UIFont systemFontOfSize:18]; 
     cellCompanyId.lineBreakMode = NSLineBreakByWordWrapping; 
     [cell addSubview:cellCompanyId]; 

     cellUsername = [[UILabel alloc] initWithFrame:CGRectMake(-20, 0, cell.frame.size.width, cell.frame.size.height)]; 
     cellUsername.backgroundColor = [UIColor clearColor]; 
     cellUsername.font = [UIFont systemFontOfSize:18]; 
     cellUsername.lineBreakMode = NSLineBreakByWordWrapping; 
     [cell addSubview:cellUsername]; 

     cellAppversion = [[UILabel alloc] initWithFrame:CGRectMake(-20, 0, cell.frame.size.width, cell.frame.size.height)]; 
     cellAppversion.backgroundColor = [UIColor clearColor]; 
     cellAppversion.font = [UIFont systemFontOfSize:18]; 
     cellAppversion.lineBreakMode = NSLineBreakByWordWrapping; 
     [cell addSubview:cellAppversion]; 

     cellServer = [[UILabel alloc] initWithFrame:CGRectMake(-20, 0, cell.frame.size.width, cell.frame.size.height)]; 
     cellServer.backgroundColor = [UIColor clearColor]; 
     cellServer.font = [UIFont systemFontOfSize:14]; 
     cellServer.lineBreakMode = NSLineBreakByWordWrapping; 
     [cell addSubview:cellServer]; 
    } 
    // Set up the cell... 
    if(indexPath.section == 0) 
    { 
     cell.textLabel.text = [LoginSetting objectAtIndex:indexPath.row]; 
     if (indexPath.row == 0) 
     { 
      cellCompanyId.textAlignment=NSTextAlignmentRight; 
      cellCompanyId.text = strCompanyid; 
     } 
     else if (indexPath.row == 1) 
     { 
      cellUsername.textAlignment=NSTextAlignmentRight; 
      cellUsername.text = strUsertxt; 
     } 
     else 
      return 0; 
    } 
    else if(indexPath.section==1) 
    { 
     cell.textLabel.text = [mic objectAtIndex:indexPath.row]; 
     if (indexPath.row == 0) 
     { 
      UISwitch *aSwitch = [[[UISwitch alloc]init]autorelease]; 
      aSwitch.frame=CGRectMake(215, 7, 0, 0); 
      [aSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; 
      [cell.contentView addSubview:aSwitch]; 
     } 
     else if (indexPath.row == 1) 
     { 
      cellAppversion.textAlignment=NSTextAlignmentRight; 
      cellAppversion.text = @"1.3.1"; 
     } 
     else if (indexPath.row == 2) 
     { 
      cellServer.textAlignment=NSTextAlignmentRight; 
      cellServer.text = mainString; 
     } 
     else 
      return 0; 
    } 
    else 
    { 
     if (indexPath.row == 0) 
     { 
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      [button addTarget:self 
         action:@selector(LogoutEvent) 
      forControlEvents:UIControlEventTouchUpInside]; 
      UIImage *buttonImage = [UIImage imageNamed:@"login_button.png"]; 
      [button setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
      button.frame = CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height); 
      [cell addSubview:button]; 
     } 
    } 
    //UITableViewCellAccessoryCheckmark 
    return cell; 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return 35.0; 
} 
내 tableViews이 xcode4에 표시됩니다 왜 이해가 안

및 xcode5 일이 아니다. 동적 프로토 타입 콘텐츠 그룹화 스타일 UITableView를 사용하고 있습니다.

+0

사용 [cell.contentView addSubview : cellCompanyId]; 대신 [cell addSubview : cellCompanyId]; cell의 모든 하위 뷰를 contentView에 추가합니다. – Savitha

+0

'if (cell == nil) {...}'문이 필요한 이유에 대해서는 언급하지 않습니다. '[tableView dequeueReusableCellWithIdentifier : CellIdentifier forIndexPath : indexPath]'는 결코 nil을 반환하지 않습니다. –

+0

@Savitha 감사합니다,하지만 작동하지 않습니다 : ( –

답변

0

메서드를 호출하기 전에 registerNib:forCellReuseIdentifier: 또는 registerClass:forCellReuseIdentifier: 메서드를 사용하여 클래스 또는 nib 파일을 등록해야합니다.

관련 문제