iOSTableView는 iOS 7에서 오프셋으로 시작합니다.
iOS 7의 일반 jane UITableView를 UIViewController로 드래그했습니다.
이제 첫 번째 셀이 시작되기 전에 공간의 수직 오프셋이 있습니다. 어떻게 제거합니까? 첫 번째 줄이 UITableView가 실제로 시작되는 곳의 위쪽 가장자리에 훨씬 더 가깝기를 원합니다. 나는 큰 오프셋을 요구하지 않았다?
어떤 아이디어?
기본적으로 테이블 뷰 컨트롤러는 컨텐츠를 탐색 모음 아래에 표시하여 컨텐츠를 스크롤하고 탐색 표시 줄 / 도구 모음 아래에서 흐리게 표시되는 컨텐츠를 볼 수 있습니다.
탐색 막대 아래에서 이동하기 위해 44 (아마 64) 픽셀에 배치하는 것처럼 보이지만 이미 이것을 보상하므로 큰 차이가 발생합니다.
IB의 스토리 보드 / xib로 이동하여 탐색 모음 항목 아래의 쇼 컨텐츠를 선택 해제하십시오.
UIViewController 의 새로운 iOS 7 구현 에는 개발자가 시스템이 UIScrollView , UITableView 및 파생에 대한 삽입을 자동으로 추가할지 여부를 선택할 수있는 새로운 옵션 세트가 있습니다 .
이 동작을 비활성화하려면 UIBuildController의 선택된 객체 관리자 에서 InterfaceBuilder의 원하는 모든 UIViewController에 대해이 확인란의 선택을 취소하십시오 .
상세 사항은:
스크롤보기의 내용 삽입을 자동으로 조정하지 않으려면 automaticAdjustsScrollViewInsets를 NO로 설정하십시오. (automaticAdjustsScrollViewInsets의 기본값은 YES입니다.)
self.automaticallyAdjustsScrollViewInsets = NO;
viewController를 닫은 후 비슷한 문제가 발생하여 tableView의 contentOffset이 (0, -64)로 변경되었습니다.
내 솔루션은 조금 이상했습니다. 다른 모든 답변을 시도했지만 성공하지 못했습니다. 내 문제를 해결 한 유일한 것은 .xib의 컨트롤 트리에서 tableView 위치를 전환하는 것이 었습니다.
다음과 같이 부모보기에서 첫 번째 컨트롤이었습니다.
ImageView 바로 다음에 tableView를 이동했으며 작동했습니다.
테이블 뷰를 첫 번째 위치에 놓으면 문제가 발생하고 테이블 뷰를 다른 위치로 이동하면 문제가 해결 된 것으로 보입니다.
PD 나는 autoLayout도 스토리 보드를 사용하지 않습니다
이것이 누군가를 도울 수 있기를 바랍니다!
그것은 비슷한 문제를 해결합니다.
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7){
tableView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);
}
이것을 사용해보십시오
tableView.separatorInset = UIEdgeInsetsZero;
분명히 iOS7보다 적은 것을 지원하는 경우 객체를 호출하기 전에 객체가이 선택기에 응답하는지 확인해야합니다.
진심으로, 변화 contentOffset
는 해결책이 아닙니다. 문제를 패치하고 원인을 수정하지 않고 있습니다. 나는 같은 문제에 직면 해 있었고 그룹화 된 tableView가 맨 위에 패딩이 있음이 밝혀졌습니다 . 필자의 경우 유형을 일반으로 설정 하면 트릭을 수행했습니다.
잘하면 그것은 몇 분을 절약합니다. 지.
아이폰 OS 9으로,이 페이지에서 다른 답변 아무도 (설정, 스토리 보드에서 예를 선택 취소 상자 나를 위해 일하지 automaticallyAdjustsScrollViewInsets
에 NO
).
내가 정말 불만족스러운 해결 방법은 다음과 같습니다.
- (void)viewDidAppear:(BOOL)animated {
self.tableView.contentOffset = CGPointMake(0.0, 0.0);
self.tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
}
같은 줄에 viewWillAppear
있거나 viewDidLoad
효과가 없었습니다.
때로는 내비게이션 컨트롤러에 내장되어 64
있을 때 테이블 뷰 상단에 높이 간격 UIViewController
이 생깁니다.
In the past, I would just re-create everything, hoping that the constraints turn out correct after a clean slate.
TIL: If you don't want to make a vertical constraint to the Top Layout Guide
, you can hold down the Option
key to access the Container Margin
.
Then make sure the Top Space to Superview
constant is set to 0
. This worked for me at least.
THis works for me:
- (void)loadView
{
[super loadView];
[self setAutomaticallyAdjustsScrollViewInsets:YES];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.frame = CGRectZero;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
If you add an empty UIView before UITableView (or any view is scrollable such as ScrollView and TextView), you can have a luck.
I had a UITableViewController embedded in a container view. To get rid of the unwanted 64 points of vertical space, I needed to uncheck the 'Adjust Scroll View Insets' in Interface Builder and set the UITableView's contentInset in my UITableViewController's viewWillAppear as below.
The size of the vertical space appears to match the navigation bar's frame height and y offset. The problem only occurred on iOS 7.
- (void)viewWillAppear:(BOOL)animated;
{
[super viewWillAppear:animated];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
const CGRect navBarFrame = self.navigationController.navigationBar.frame;
const CGFloat blankVerticalSpace = navBarFrame.origin.y + navBarFrame.size.height;
self.tableView.contentInset = UIEdgeInsetsMake(-blankVerticalSpace, 0, 0, 0);
}
}
In Xamarin iOS, I had this issue occuring on a backgrounded UITableViewController just after the foreground modal dialog was being dismissed. In the process of moving into the foreground, the UITableViewController had insets set (somewhere by iOS):
This class solved it
public class UITableViewControllerWithBugFix : UITableViewController {
public UITableViewControllerWithBugFix(UITableViewStyle withStyle) : base(withStyle) {
}
public override void ViewWillLayoutSubviews() {
if (TableView.ContentInset.Top != 0.0f)
TableView.ContentInset = UIEdgeInsets.Zero;
if (TableView.ScrollIndicatorInsets.Top != 0.0f)
TableView.ScrollIndicatorInsets = UIEdgeInsets.Zero;
base.ViewWillLayoutSubviews();
}
}
From time to time I get back to this awful situation, and I notice that it's still quite unknown. So, for future memory...
Lately, I'm fixing with this workaround.
- Add a subview at the top of the UITableView, with zero pixel height. Works with Autolayout or without.
- If I feel confident :-) I remove this fake view, fix the constraints on the top, and magically it works.
Don't ask me why, I still think it's a bug deep in UIKit.
If you go to storyboard, you can change the offset by selecting the table and under the Table View section in the Attributes inspector you just change the Separator Insets on the left to 0.
I think the real solution is to set up your top and bottom constraints on the tableview be equal to the topMargin and bottomMargin. Not the top layout guide and bottom layout guide. This allows you to keep automaticallyAdjustsScrollViewInsets to be true.
Swift 3 solution:
class PaddingLessTableView : UITableView
{
override func headerView(forSection section: Int) -> UITableViewHeaderFooterView?
{
return nil
}
override func footerView(forSection section: Int) -> UITableViewHeaderFooterView?
{
return nil
}
}
If you embedded your TableViewController in a NavigationController or a ContainerView, You have to constraint to margins instead of top Layout guide in Storyboard
. Check constraint to margins when you are doing the constraints
No other way worked for me. I couldn't comment so I'm just reiterating on Robert Chens answer.
I tried several of the answers. Changing the settings in storyboard caused ripple problems with an overlay menu that pops in from the left.
I only have a blank UIViewController in storyboard, otherwise everything is programmatically generated.
I have same problem with a UITableView inside a UIView inside a UIViewController. Namely, the section headers start too far down when the UIViewController is embedded in a Navigation Controller. W/o the navigation controller everything works fine.
To fix the problem I created a UILabel and with constraints placed the UILabel bottom constraint = the top constraint of the UIView (so it does not show on the screen. Now with that additional control (the new Label) the TableView behaves properly.
inputsContainerView.addSubview(titleLabel)
inputsContainerView.addSubview(tableView)
// inputsContainerView
///////////////////////////////////////
inputsContainerView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
inputsContainerView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 0).isActive = true
inputsContainerView.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -40).isActive = true
inputsContainerView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.7).isActive = true
// tableView
///////////////////////////////////////
tableView.centerXAnchor.constraint(equalTo: inputsContainerView.centerXAnchor).isActive = true
tableView.topAnchor.constraint(equalTo: inputsContainerView.topAnchor).isActive = true
tableView.widthAnchor.constraint(equalTo: inputsContainerView.widthAnchor).isActive = true
tableView.heightAnchor.constraint(equalTo: inputsContainerView.heightAnchor).isActive = true
// titleLabel - inserted to stop bad section header behavior
///////////////////////////////////////
titleLabel.centerXAnchor.constraint(equalTo: inputsContainerView.centerXAnchor).isActive = true
titleLabel.bottomAnchor.constraint(equalTo: inputsContainerView.topAnchor).isActive = true
titleLabel.widthAnchor.constraint(equalTo: inputsContainerView.widthAnchor).isActive = true
titleLabel.heightAnchor.constraint(equalToConstant: 20).isActive = true
I had a same problem in iOS 11 and xib, UITableviewController and I solved it as below
[self.tableView setContentInset:UIEdgeInsetsMake(-44,0,0,0)];
참고URL : https://stackoverflow.com/questions/18388429/uitableview-is-starting-with-an-offset-in-ios-7
'Programing' 카테고리의 다른 글
쉘 스크립트에서 대소 문자를 구분하지 않는 문자열 비교 (0) | 2020.07.22 |
---|---|
EditText에 대한 자동 제안을 끄시겠습니까? (0) | 2020.07.22 |
Java에서 int의 스트림을 char의 스트림으로 변환 (0) | 2020.07.22 |
Cordova : 특정 iOS 에뮬레이터 이미지 시작 (0) | 2020.07.22 |
Android Retrofit 라이브러리에서 수업 용 변환기를 만들 수 없습니다. (0) | 2020.07.22 |