通常我们使用
@interface interface_name : parent_class <delegates>
{
......
}
@end
Run Code Online (Sandbox Code Playgroud)
在.h文件和.m文件中的方法中,我们合成了在.h文件中声明的变量的属性.
但是在某些代码中,这个@interface ..... @ end方法也保存在.m文件中.这是什么意思?他们之间有什么区别?
还要提供一些关于.m文件中定义的接口文件的getter和setter的话.
提前致谢
我想知道为什么有两次@interface.一个在class.h和另一个class.m.例如:
TestTableViewController.h:
#import <UIKit/UIKit.h>
@interface TestTableViewController : UITableViewController
@end
Run Code Online (Sandbox Code Playgroud)
和(自动生成)class.m我发现:
#import "TestTableViewController.h"
@interface TestTableViewController ()
@end
@implementation TestTableViewController
... methods delegated from UITable delegates
@end
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,什么@interface TestTableViewController ()中.m的文件是什么.为什么会这样?我需要它吗?
提前致谢
可能重复:
.h和.m文件中@interface定义的区别在iOS 5项目中使用的.m文件
中的@interface声明是什么?
我见过这样的代码:
// In Header.h
@interface Header{}
@end
// In Header.m
@interface Header()
@end
Run Code Online (Sandbox Code Playgroud)
我的问题是:
在上一个版本的ox xCode(4.3)中,我看到了预定义模板(例如我们的主/明细模板),其中在.m文件中进行了接口声明.例如,在文件MyFile.h中有:
@interface MyFile
@property (nonatomic, retain) NSString *someProp;
@end
Run Code Online (Sandbox Code Playgroud)
在MyFile.m文件中有:
@implementation MyFile
@interface MyFile {
NSString * anotherProp;
}
- (id) init...
Run Code Online (Sandbox Code Playgroud)
为什么这样做?为什么没有将anotherProp声明为MyFile.h文件?
提前致谢
objective-c ×4
ios ×2
getter ×1
header-files ×1
interface ×1
ios5 ×1
setter ×1
xcode ×1
xcode4.4 ×1