OGeek|极客世界-中国程序员成长平台

标题: ios - 重新定位 UITableView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:40
标题: ios - 重新定位 UITableView

我有一个 View Controller

  1. subview (主视图大小的一半)
  2. 表格 View (主视图大小的一半)
  3. 导航栏按钮

单击按钮时,我希望隐藏 subview 并以完整的主视图大小显示表格 View ....它在下面的代码中运行良好,但不是第一次。 当我第一次单击栏按钮时,它会隐藏 subview 并调整表格 View 的大小,但不会在屏幕上显示结果(适用于所有时间)。 如果我在第一次单击导航栏之前滚动表格 View ,它可以正常工作......我认为它与表格 View 加载有关,我无法理解

代码

if(isMapVisible==YES) {
    [mapView setHidden:YES];
    [tblView setFrame:CGRectMake(self.view.frame.origin.x,
                                 self.view.frame.origin.y+self.navigationController.navigationBar.frame.size.height+[UIApplication sharedApplication].statusBarFrame.size.height,
                                 self.view.frame.size.width, 
                                 self.view.frame.size.height-self.navigationController.navigationBar.frame.size.height-[UIApplication sharedApplication].statusBarFrame.size.height-self.navigationController.tabBarController.tabBar.frame.size.height)];

    isMapVisible=NO;
} else {
    [mapView setHidden:NO];
    [tblView setFrame:CGRectMake(mapView.frame.origin.x,
                                 mapView.frame.origin.y+mapView.frame.size.height+1,
                                 mapView.frame.size.width,
                                 mapView.frame.size.height)];

    isMapVisible=YES;
}


- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

    activityCell *cell = (activityCell*)[tableView dequeueReusableCellWithIdentifier"activityCell" forIndexPath:indexPath];

    return cell;
}
- (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section {
    return 10;
}

- (CGFloat)tableViewUITableView *)tableView heightForRowAtIndexPath:    (NSIndexPath *)indexPath {
    return 100;
}



Best Answer-推荐答案


这样调用你的方法

[self performSelectorselector(methodToChangeTableViewFrame) withObject:nil afterDelay:0.1f];

-(void)methodToChangeTableViewFrame {

        // Here your code
    if(isMapVisible==YES) {
        [mapView setHidden:YES];
        [tblView setFrame:CGRectMake(self.view.frame.origin.x,
                                     self.view.frame.origin.y+self.navigationController.navigationBar.frame.size.height+[UIApplication sharedApplication].statusBarFrame.size.height,
                                     self.view.frame.size.width, 
                                     self.view.frame.size.height-self.navigationController.navigationBar.frame.size.height-[UIApplication sharedApplication].statusBarFrame.size.height-self.navigationController.tabBarController.tabBar.frame.size.height)];

        isMapVisible=NO;
    } else {
        [mapView setHidden:NO];
        [tblView setFrame:CGRectMake(mapView.frame.origin.x,
                                     mapView.frame.origin.y+mapView.frame.size.height+1,
                                     mapView.frame.size.width,
                                     mapView.frame.size.height)];

        isMapVisible=YES;
    }
}

关于ios - 重新定位 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31070355/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4