Ios 使用if语句为设备声明不同的类
有没有可能写出下面这样的东西Ios 使用if语句为设备声明不同的类,ios,objective-c,Ios,Objective C,有没有可能写出下面这样的东西 // MasterViewController.h #import <UIKit/UIKit.h> if (device == iPad) @interface MasterViewController : UIViewController else @interface MasterViewController : UITableViewController //MasterViewController.h #进口 如果(设备=
// MasterViewController.h
#import <UIKit/UIKit.h>
if (device == iPad)
@interface MasterViewController : UIViewController
else
@interface MasterViewController : UITableViewController
//MasterViewController.h
#进口
如果(设备==iPad)
@界面MasterViewController:UIViewController
其他的
@界面主视图控制器:UITableViewController
换句话说,一个通用应用程序是否可能是不同视图控制器的子类取决于设备?不要尝试创建这样的单个类,而是创建两个类:
@interface MasterViewController_iPhone : UIViewController
及
然后在代码中使用设备习惯用法来决定实例化哪一个:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// create a MasterViewController_iPhone
} else {
// create a MasterViewController_iPad
}
不要尝试创建这样的单个类,而是创建两个类:
@interface MasterViewController_iPhone : UIViewController
及
然后在代码中使用设备习惯用法来决定实例化哪一个:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// create a MasterViewController_iPhone
} else {
// create a MasterViewController_iPad
}
不,你不能。用运行时数据声明compiletime是不正确的。不要在运行时声明不同的类,实例化不同的类。@CodaFi你能在回答中详细说明实例化吗?使用主详细信息模板。几乎所有的设计都是用IB完成的。在iPhone上使用TableViewController效果更好,但我希望iPad上有足够的空间,因此是一个ViewController。不。你不能。用运行时数据声明compiletime是不正确的。不要在运行时声明不同的类,实例化不同的类。@CodaFi你能在回答中详细说明实例化吗?使用主详细信息模板。几乎所有的设计都是用IB完成的。在iPhone上使用TableViewController效果更好,但我想要iPad上的“空间”,因此是一个ViewController。