Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView自动错位_Ios_Objective C_Uitableview_Ios7 - Fatal编程技术网

Ios UITableView自动错位

Ios UITableView自动错位,ios,objective-c,uitableview,ios7,Ios,Objective C,Uitableview,Ios7,问题 - (void)viewDidLoad { [super viewDidLoad]; self.navigationController.navigationBarHidden = FALSE; [self.navigationController.topViewController.navigationItem setHidesBackButton:YES]; [self.view setBackgroundColor:[UIColor clearColo

问题

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = FALSE;
    [self.navigationController.topViewController.navigationItem setHidesBackButton:YES];
    [self.view setBackgroundColor:[UIColor clearColor]];
    _extrasTable = [[UITableView alloc] initWithFrame:CGRectMake(50, 44, CGRectGetWidth(self.view.frame) - 75, CGRectGetHeight(self.view.frame) - 44) style:UITableViewStylePlain];
}

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [_extrasTable setBackgroundColor:[UIColor clearColor]];
    _extrasTable.rowHeight = CGRectGetHeight(_extrasTable.bounds) / 5;
    _extrasTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    _extrasTable.dataSource = self;
    _extrasTable.delegate = self;
    [self.view addSubview:_extrasTable];];
}

#pragma mark - UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [EXTRAS count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        }
        cell.textLabel.font = [UIFont fontWithName:NobileMedium size:15];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.text = EXTRAS[indexPath.row];
        [cell setBackgroundColor:[UIColor clearColor]];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
    }

#pragma mark - Visible cells
- (NSArray*)visibleCells
{
    return [_extrasTable visibleCells];
}
我在
UITableView
中遇到了一个奇怪的问题。以下是视频链接,解释了我面临的问题。(打开慢速动画)

只有第一次访问控制器时,工作台才会错位。后来,这个问题没有突然出现

代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = FALSE;
    [self.navigationController.topViewController.navigationItem setHidesBackButton:YES];
    [self.view setBackgroundColor:[UIColor clearColor]];
    _extrasTable = [[UITableView alloc] initWithFrame:CGRectMake(50, 44, CGRectGetWidth(self.view.frame) - 75, CGRectGetHeight(self.view.frame) - 44) style:UITableViewStylePlain];
}

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [_extrasTable setBackgroundColor:[UIColor clearColor]];
    _extrasTable.rowHeight = CGRectGetHeight(_extrasTable.bounds) / 5;
    _extrasTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    _extrasTable.dataSource = self;
    _extrasTable.delegate = self;
    [self.view addSubview:_extrasTable];];
}

#pragma mark - UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [EXTRAS count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        }
        cell.textLabel.font = [UIFont fontWithName:NobileMedium size:15];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.text = EXTRAS[indexPath.row];
        [cell setBackgroundColor:[UIColor clearColor]];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
    }

#pragma mark - Visible cells
- (NSArray*)visibleCells
{
    return [_extrasTable visibleCells];
}
编辑

我正在将此TableView控制器作为子视图添加到另一个视图控制器。其代码如下所示:

for (UIView *view in [self.view subviews]) {
    [view removeFromSuperview];
}
[self.navigationController setNavigationBarHidden:NO];
[self.navigationController.topViewController.navigationItem setHidesBackButton:YES];
[currentController removeFromParentViewController];//currentController - instance of UIViewController
MMExtrasVC *controller = [[MMExtrasVC alloc] init];//the controller that contains table view
controller.view.frame = [[self view] bounds];
[self.view addSubview:controller.view];
[self addChildViewController:controller];
[controller didMoveToParentViewController:self];
currentController = controller;

实现
viewdilayoutsubview
并在那里为您的表设置框架

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    _extrasTable setFrame:CGRectMake(x, y, width, height)];
}

我认为问题是由导航栏引起的

首先,我将尝试从viewDidLoad中删除以下内容:

self.navigationController.navigationBarHidden = FALSE;
其次,我将删除以下内容中的勾号(如果有):


从视图控制器的属性检查器中执行。

Did。还是有同样的问题!您是否使用带约束的界面生成器和/或情节提要?您还可以将代码发布到ViewController所在的位置吗instanciatied@Marc-我没有使用xib/故事板。将更新帖子以显示初始化代码。已删除
self.navigationController.navigationBarHidden=FALSE,同一问题。不使用,故事板/xib。在主情节提要中更改-没有效果!