1,手动载入XIB文件需要使用NSBundle类。该类是应用和包含应用的程序包之间的接口,通过它可以得到程序包中的文件。应用启动时会创建一个NSBundle实例。向NSBundle发送mainBundle可以得到指向该实例的指针。
得到指向主NSBundle对象的指针后,就可以要求其载入某个XIB文件。实现ItemsViewController.m中的headerView方法,代码如下:
- (UIView*)headerView
{
//如果还没载入headerView
if(!headerView) {
//载入headerView.xib
[[NSBunder mainBundle] loadNIbNamed:@"HeaderView" owner:self options:nil];
}
return headerView;
}
2,
//判断设备是否IPHONE5, iphone6呢?
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
//动态获取设备高度
#define IPHONE_HEIGHT [UIScreen mainScreen].bounds.size.height
3,
如何得到资源文件myImage.png的路径?
NSString *path = [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"];
NSBundle实例会先检查程序包的根目录,查找是否有myImage.png文件。如果有,就返回该文件的全路径。如果没有,则NSBundle实例会根据设备的语言设置在相应lproj目录下继续查找。如果还是找不到,就返回nil。
4,
运行 ibtool 命令时,如遇到如下错误:
Error: No developer directory found at /Developer. Run /usr/bin/xcode-select to update the developer directory path.
那么先运行命令 sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
即可解决。
------------
ibtool是一个nib资源文件本地化的小工具:
1.从nib文件里面提取可以被本地化的字符串。 可以通过如下的命令在终端里面处理:
ibtool --generate-stringsfile MyNib.strings MyNib.nib
2.等翻译好了字符串以后,就需要通过ibtool去把字符串合并到.nib文件里面去。 具体的命令如下:
ibtool --strings-file MyNib.strings --write MyNewNib.nib MyNib.nib
其中MyNib.nib是你想修改的xib文件。
5,
设置了textFieldShouldReturn,点击return,键盘隐藏
步骤:
a,设置UITextFieldDelegete
@interface DoubleViewController : UIViewController<UITextFieldDelegate>{
UserInfo *userBoy;
UserInfo *userGirl;
}
b,.m文件中对应的委托方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if (textField == name_boy) {
[name_boy resignFirstResponder];
}
else if (textField == birthday_boy) {
[birthday_boy resignFirstResponder];
}
else if (textField == name_girl) {
[name_girl resignFirstResponder];
}
else if (textField == birthday_girl) {
[birthday_girl resignFirstResponder];
}
return YES;
}
3,最后一步,也是关键一步,设置委托。要不就不生效。