成功裏に終了した Apple チュートリアル (BirdSighting) を自分のアプリに変更することで、iOS プロジェクトの優れた MVC プラクティスを学ぼうとしています。彼らは、Model と Controller の NSObject クラスを作成しました。最初の ViewController は TableVC です。appDelegate.mでは、 firstViewController をdataControllerに接続して didFinishLaunchingWithOptionsを変更 しました。私のアプリでは、最初の ViewController をテーブルにするのではなく、単なる基本的な VC にしたいと考えています。警告が表示されます: Incompatible Pointer Types。そのコードは次のとおりです。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
// enterView is initial UIViewController
enterView *firstViewController = (enterView *)[[navigationController viewControllers] objectAtIndex:0];
// dBcontrols is a NSObject class
dBcontrols *aDataController = [[dBcontrols alloc] init];
firstViewController.dataController = aDataController; // <-- ERROR Here.
return YES;
}
私の最初の ViewController であるenterViewのヘッダーには、次のように記述されています。
@class contacts;
@class dBcontrols;
@interface enterView: UIViewController
@property (strong, nonatomic) enterView *dataController;
モデル クラスの連絡先とコントローラーの dBcontrols は、Apple のチュートリアルと実質的に同じです。しかし、ViewController は Controller にアクセスしていません。enterView.mには次の行があります。
#import "enterView.h"
#import "contacts.h"
#import "dBcontrols.h"
@interface enterView ()
@end
@synthesize dataController = _dataController;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSInteger cntC = [self.dataController countContacts]; <-- ERROR here
NSLog(@"number of contacts = %d", cntC );
}
次のようなエラーがあります: No visible interface declares the selector 'countContacts' , これは dBcontrols.m にある Controller メソッドです。
- (NSUInteger)countContacts {
return [self.masterContactList count];
}
ヘッダーの内容は次のとおりですdBcontrols.h :
@class contacts;
@interface dBcontrols: NSObject
- (NSUInteger)countContacts;
. . .
@end
最初の VC として TableVC から Basic VC に切り替えたことが問題の原因ですか? それがチュートリアルからの唯一の関連する変更だと思います。どうすれば修正できますか?十分な情報を提供できたことを願っています。どうもありがとう!リック