iOS 开发过程中遇到问题常用的解决办法汇总

1、让控制器的视图从导航栏下开始算起

self.edgesForExtendedLayout = UIRectEdgeNone;

2、self.title = @"" 时导致标签栏title消失,如下图所示

iOS 开发过程中遇到问题常用的解决办法汇总_第1张图片

原因:

self.navigationItem.title = @"my title";//只设置导航控制器标题
self.tabBarItem.title= @"my title"; //只设置底部四大金刚标题
self.title= @"my title";//两者都会设置,并且只要你调用会覆盖上面两者设置的值

3、当跳转控制器后发现视图底部空出TabBar的高度,则可以在跳转时添加下面红色的代码。

FavouritesTabBar *vc = [[FavouritesTabBar alloc]init];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];

4、获取当前视图所在的控制器

- (UIViewController *)parentController:(UIView *)view
{
    UIResponder *responder = [view nextResponder];
    while (responder) {
        if ([responder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)responder;
        }
        responder = [responder nextResponder];
    }
    return nil;
}

5、获取日期格式

NSDate *date = [NSDate date];//当前时间
NSDate *lastDay = [NSDate dateWithTimeInterval:-24*60*60 sinceDate:date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekday | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *comps = [calendar components:unitFlags fromDate:lastDay];



你可能感兴趣的:(iOS)