我已经浏览了bees4honey、iadsuites 样本(全部三个),以及大家最喜欢的raywenderlich 导师。他们都没有帮助我展示横幅。我没有大多数导师通常提到的任何xib。这是我的委托代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
// Create the window object
UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Assign the localWindow to the AppDelegate window, then release the local window
self.window = localWindow;
[localWindow release];
// Setup the first view controller
HomeViewController *homeViewController = [[HomeViewController alloc] init];
// Initialise the navigation controller with the first view controller as its root view controller
navigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController.navigationBar setTintColor:[UIColor blackColor]];
//[navigationController setNavigationBarHidden:YES];
[HomeViewController release];
// Add the navigation controller as a subview of our window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
我有 HomeViewController(用于导航和方法)和 HomeView(用于子视图)。我的 homeviewcontroller.m 示例
#pragma mark -
#pragma mark Initialisation
- (id)init {
self = [super init];
if (self) {
self.title = @"Home";
UIView *homeView = [[HomeView alloc] initWithParentViewController:self];
self.view = homeView;
[homeView release];
}
return self;
}
#pragma mark -
#pragma mark Action Methods
- (void)button3Action {...........rest of code below as method for the button located in HomeView.m
来自 Homeview.m 的示例代码
// Private Methods
@interface HomeView()
- (void)loadButton3;
@end
@implementation HomeView
#pragma mark -
#pragma mark Initialization
- (id)initWithParentViewController:(HomeViewController *)parent {
if ((self = [super init])) {
// Update this to initialize the view with your own frame size
// The design has specified that there is to be no status bar present,
// please hide the status bar.
[self setFrame:CGRectMake(0, 0, 320, 480)];
// Assign the reference back to the parent view controller
refParentViewController = parent;
// Set the view background color
[self setBackgroundColor:[UIColor lightGrayColor]];
// Load subview methods
[self loadButton3];
}
return self;
}
#pragma mark -
#pragma mark Load Subview Methods
- (void)loadButton3 {
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button3 setTitle:@"Is that counterfeit product?" forState:UIControlStateNormal];
[button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button3 setBackgroundColor:[UIColor clearColor]];
button3.titleLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:25];
[button3 addTarget:refParentViewController action:@selector(button3Action) forControlEvents:UIControlEventTouchUpInside];
[button3 setFrame:CGRectMake(5, 375, 310, 31)];
[self addSubview:button3];
}
如果有人可以帮助我找出我需要将“苹果批准的代码”放在我的项目中以显示横幅的确切位置,那就太好了。
谢谢 =)