iOS 上的坑们

怎样不显示 UITableView 末尾的空白行?

1
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

Autolayout 如何动画?

1
2
3
4
5
[containerView layoutIfNeeded]; // Ensures that all pending layout operations have been completed
[UIView animateWithDuration:1.0 animations:^{
// Make all constraint changes here
[containerView layoutIfNeeded]; // Forces the layout of the subtree animation block and then captures all of the frame changes
}];

-[UICTFont set]: unrecognized selector sent to instance

检查 AttributedString 的 AttributeName 与值类型是否匹配。

Unable to load string table file: *** <fileName> Cocoa error 3840

工程中有重复的 .strings 文件,在 Xcode 中搜索 ,删除其中一个,或者改名。

如何获取 AutoLayout 之后的 View 的 frame size?

1
2
3
4
- (void)layoutSubviews {
[self layoutIfNeeded];
// Get frame size here, may get called several times
}

如何隐藏 UINavigationBar 上返回按钮的文字?

将 UINavigationController > UIBarButtonItem > Title 设置成一个空格符组成的字符串就好。

Xcode 7 编译时产生大量 warning

编译时产生大量的 warning

1
warning: /Users/username/Library/Developer/Xcode/DerivedData/ModuleCache/1UIOVPNM0I1EA/Darwin-38I6DLZ5IH61J.pcm: No object file for requested architecture

让提供 SDK 的一方将 build settings 里面的 CLANG_ENABLE_MODULE_DEBUGGING 设置成 NO 即可。

参考这里

如何隐藏 Status bar?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- (void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}

// Add this method
- (BOOL)prefersStatusBarHidden {
return YES;
}

怎么点击 self.view 就让键盘收起?

1
2
3
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}

查看 .mobileprovision 文件内容

1
$ security cms -D -i "Payload/YourApp.app/embedded.mobileprovision"
给鸡排饭加个蛋