【发布时间】:2015-10-07 06:46:25
【问题描述】:
我将表格视图单元格 XIB 名称声明为 NSString 常量。 iPad 和 iPhone 有单独的 XIB,我想使用相同名称的常量但值不同来引用两个版本的 XIB。
BaseViewController.h
#import <UIKit/UIKit.h>
extern NSString * const FileCell;
extern NSString * const FolderCell;
BaseViewController.m
#import "BaseViewController.h"
//I am sure that this cannot be done
//since I cannot check device type at preprocessing time/compile time
#if IS_IPAD_DEVICE// device check, not viable
NSString * const FileCell = @"FileCell";
NSString * const FolderCell = @"FolderCell";
#else
NSString * const FileCell = @"FileCell~iPhone";
NSString * const FolderCell = @"FolderCell~iPhone";
#endif
//I don't want to declare separate constants with different names for iPhone table view cells.
//I want to use same name of constants but the string values are different for iPad and iPhone.
@implementation BaseViewController
-(void)viewDidLoad
{
[super viewDidLoad];
[self.collectionView registerNib:[UINib nibWithNibName:FileCell bundle:nil] forCellWithReuseIdentifier:FileCell];
[self.collectionView registerNib:[UINib nibWithNibName:FolderCell bundle:nil] forCellWithReuseIdentifier:FolderCell];
}
许多其他文件和子控制器也使用这些常量。 知道我该如何完成这件事。我不想使用属性并覆盖它们的吸气剂。一些优雅的解决方案?
【问题讨论】:
标签: ios objective-c iphone ipad constants