UITableView导航控制器节索引在导航标题后对齐

UITableView导航控制器节索引在导航标题后对齐,uitableview,uinavigationbar,collation,alignment,indexed,Uitableview,Uinavigationbar,Collation,Alignment,Indexed,在分区索引UITableView中,如何使所选分区的标题(通过按分区索引)在屏幕顶部(导航控制器下)对齐,而不是在顶部的导航栏标题后对齐 像这样: [按钮]屏幕顶部的导航栏标题[其他按钮] X(部门信函) 第…节内的项目 需要说明的是,我遇到的问题是,当按下右侧的节索引时,表格会将该节滚动到屏幕的最上方,隐藏在导航栏下方。我希望在导航标题触摸导航栏底部边框和节字母行的顶部后,精确地显示节标题-例如,当表格第一次出现时。更好的解决方案: a) 睡一会儿 b) 请注意,在您睡觉时,'uibar

在分区索引UITableView中,如何使所选分区的标题(通过按分区索引)在屏幕顶部(导航控制器下)对齐,而不是在顶部的导航栏标题后对齐

像这样:
[按钮]屏幕顶部的导航栏标题[其他按钮]
X(部门信函)
第…节内的项目

需要说明的是,我遇到的问题是,当按下右侧的节索引时,表格会将该节滚动到屏幕的最上方,隐藏在导航栏下方。我希望在导航标题触摸导航栏底部边框和节字母行的顶部后,精确地显示节标题-例如,当表格第一次出现时。

更好的解决方案:

a) 睡一会儿

b) 请注意,在您睡觉时,'uibarstyleblacktransparent'的使用已被弃用,因此只需执行以下操作:

  • 在Interface Builder中打开MainWindow.xib,在“选项卡栏控制器”中的“导航控制器”中选择“UINavigationBar”项,并将“样式”更改为“黑色不透明”,而不是半透明
  • 在UITableViewController类文件中,写入

    - (void)viewWillDisappear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = YES; /* Yes, go underneath the Navigation Bar elsewhere if you want to. */
    [super viewWillDisappear:animated];
    }
    - (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = NO; /* No going underneath the Navigation Bar. Problem solved! */
    ...
        [super viewWillAppear:animated];
    }
    
c) 不要感到尴尬,而是要意识到睡眠现在是你武器库中一种更有用的编码技术;P
正确解决方案的线索:

“导航控制器从不在不透明的导航栏下显示内容。”

“将导航控制器的“半透明”属性设置为“是”。这将允许您的内容在导航栏的下方显示。”

请参阅:developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html

参见:developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationBar_Class/Reference/UINavigationBar.html#//apple_ref/occ/instp/UINavigationBar/半透明

UIBarStyle定义了不同类型视图的样式外观

UIBarStyleBlackTranslucent=2,//已弃用

使用UIBarStyleBlack并将半透明属性改为“是”


睡觉前,把它修好。“艰难之路”

- (void)correctFrame:(UIView *)viewWithWrongFrame {
    CGRect correctedFrame = [[viewWithWrongFrame superview] frame];
    correctedFrame.size.height = correctedFrame.size.height - self.navigationController.navigationBar.frame.size.height; /* Height without Navigation Bar */
    correctedFrame.origin.y = correctedFrame.origin.y + self.navigationController.navigationBar.frame.size.height; /* Origin below Navigation Bar */
    [viewWithWrongFrame setFrame:correctedFrame];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    ...
    [self correctFrame:[self.navigationController.view.subviews objectAtIndex:0]]; /* Correct the frame so it is after the Navigation Bar */
    [self.tableView setContentInset:UIEdgeInsetsMake(-self.navigationController.navigationBar.frame.size.height, 0, 0, 0)]; /* Eliminate initial blank space at top.*/
    ...
}

- (void)cleanDisplay {
    [self.tableView setContentInset:UIEdgeInsetsZero]; /* Fix difference between horizontal and vertical orientation. */
    ...
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
    [self correctFrame:[self.navigationController.view.subviews objectAtIndex:0]]; /* Correct the frame so it is after the Navigation Bar */

    /* Clean the display after turning... */
    [self performSelectorOnMainThread:@selector(cleanDisplay) withObject:nil waitUntilDone:NO];
}
- (void)viewWillAppear:(BOOL)animated {
    ...
    [self performSelectorOnMainThread:@selector(cleanDisplay) withObject:nil waitUntilDone:NO];
    ...
}
请注意,失败的方法包括:

使用界面生成器将UITableView嵌入到UIView中。不起作用,因为它会自动调整到全高。 调整[self.tableView superview].frame=CGRectInset([self.tableView superview].frame,44,44)的大小; 或者,边界没有影响, self.tableView.frame和.bounds都没有

当我尝试时,发现了错误的线索: self.navigationController.view.frame=CGRectInset(self.navigationController.view.frame,20,44); 这实际上改变了包含表的视图的大小。显然,将子视图更改为该子视图将修复原始问题

用上面的方法修复了它。尽管在向后或向前移动到其他屏幕之前,更改需要恢复到正常状态,以避免在其他位置移动元素