2011-10-05 4 views
0

내 애플리케이션에 스플릿 뷰가 있으며 가로 모드에서만 활성화됩니다. masterview에서 내가 tableview 있고 마지막 섹션에서 사용자 지정 단추가 있습니다. 문제는 장치 방향을 사용하는 대신 단추 너비가 potrait로 유지된다는 것입니다. 단추 및 뷰에서 setAutoresizingMask를 사용하여 재생하려고했지만 그 중 하나가 작동하지 않습니다.iPad, viewForHeaderInSection의 맞춤 크기 조정 버튼

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) sectionNum { 
    if (sectionNum == 4) { 
     CGRect frameSize; 

     if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) { 
      frameSize = CGRectMake(45.0, 0.0, 600.0, 44.0); 
     } else { 
      frameSize = CGRectMake(45.0, 0.0, 680.0, 44.0); 
     } 

     UIView *btnView = [[[UIView alloc] initWithFrame:frameSize] autorelease]; 

     // button 
     UIButton* btnFind = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [btnFind setBackgroundImage:[[UIImage imageNamed:@"buttonblue.png"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:0.0] forState:UIControlStateNormal]; 
     [btnFind setBackgroundImage:[[UIImage imageNamed:@"buttonred.png"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:0.0] forState:UIControlStateHighlighted]; 

     btnFind.frame = frameSize; 
     btnFind.tag = 1; 

     [btnFind setTitle:@"Find" forState:UIControlStateNormal]; 
     [btnFind addTarget:self action:@selector(doSearchDoc:) forControlEvents:UIControlEventTouchUpInside]; 
     //[btnFind setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin]; 

     //[btnView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 
     [btnView addSubview:btnFind]; 

     return btnView; 
    } 

    return nil; 
} 

이 문제를 해결할 방법을 알려주세요.

감사합니다.

답변

1

기기를 회전 할 때 헤더가 새로 고쳐지지 않은 다른 문제가 발생했습니다. 위의 방법은 내 상황에서 호출되지 않았습니다, 당신도 이것이 당신을위한 경우인지 확인할 수 있습니다. 사용자가 더 나은 0.5을 수락 할 때 일반적으로 시간이 장치 만 ITIS를 회전 할 때 전체 다시로드를 줄 수있는 경우에

물론
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    // This solves an issue that the header doesn't show when roating device (ok on simulator) 
    NSIndexPath* ipselected = [self.tableView indexPathForSelectedRow]; 
    [self.tableView reloadData]; 
    [self.tableView selectRowAtIndexPath:ipselected animated:false scrollPosition:UITableViewScrollPositionMiddle]; 
} 

이 가능하다 : 나는 채택 해결책은 회전 방법에 reloadData를 호출했다 그/그녀는 장치를 이동하는 것으로 바쁠 때 지연.

위의 방법으로 굳이 아이어를 단추에 붙이고 프레임을 변경할 수 있습니다.

+0

감사합니다. 이것은 멋지게 작동합니다. – Inoel

+0

제 경우이 더 잘 작동합니다. 코드를 수정하고 .reloadSections를 .reloadData로 바꿉니다. [NSIndexSet indexSetWithIndex : btnSectionIndex] withRowAnimation : NO]; – Inoel

관련 문제