【发布时间】:2013-07-05 01:42:25
【问题描述】:
我正在尝试通过将我已成功完成的 Apple 教程 (BirdSighting) 修改到我自己的应用程序中来为我的 iOS 项目学习良好的 MVC 实践。他们为模型和控制器构建了 NSObject 类。他们的第一个 ViewController 是 TableVC。在 appDelegate.m 中,他们通过将 firstViewController 连接到 dataController 来更改 didFinishLaunchingWithOptions。在我的应用程序中,我不希望我的第一个 ViewController 是一个表,而只是一个基本的 VC。我收到警告:不兼容的指针类型。这是代码:
- (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 declarations selector 'countContacts',这是 dBcontrols.m 中的 Controller 方法,如下所示:
- (NSUInteger)countContacts {
return [self.masterContactList count];
}
这是标题中的内容,dBcontrols.h:
@class contacts;
@interface dBcontrols: NSObject
- (NSUInteger)countContacts;
. . .
@end
我的问题是从 TableVC 切换到作为第一个 VC 的基本 VC 引起的吗?我认为这是本教程中唯一相关的更改。我该如何解决?我希望我已经提供了足够的信息。 非常感谢! 瑞克
【问题讨论】:
标签: ios xcode uiviewcontroller appdelegate