在MainViewController.h, 你会发现这个类有两个实例变量:
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
NSOperationQueue *queue;
NSMutableString *currentStringValue;
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar;
@end
一个类公开的接口中,不是放实例变量的一个好地方。通常,实例变量是你类内部的一部分,不是你想暴露给公共接口的。 对你这个类的用户来说, 知道它的实例变量不是那么重要。 从数据隐藏的角度来看, 如果我们能将这些实现放到这个类的 @implementation 部分中才是更好。
我很高兴的告诉你,现在在 LLVM 3.0 编译器中,这个是可以实现的。
从 MainViewController.h 中删除实例变量块, 把他们放到 MainViewController.m 中。 这个头文件看起来应该是这样:
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar;
@end
MainViewController.m 的顶部看起来应该是这样:
@implementation MainViewController
{
NSOperationQueue *queue;
NSMutableString *currentStringValue;
}
构建应用。。。 它能正常工作。 这让 .h 文件更加清晰。