Xcode / iPhone: первое приложение для Windows - почему ничего не отображается в представлениях TabBarController - PullRequest
1 голос
/ 25 июня 2011

Есть ли что-то, что мне нужно помнить при использовании шаблона на основе Windows? Потому что мне неясно, почему вкладки отображаются, но ничего в представлениях не отображается.

Не могли бы вы помочь? Потому что я искал предыдущие вопросы в течение нескольких часов и до сих пор не нашел ничего, что могло бы прояснить это.

AnotherMadeUpAppDelegate.h

#import <UIKit/UIKit.h>
#import "AnotherMadeUpViewController.h"

@interface AnotherMadeUpAppDelegate : NSObject <UIApplicationDelegate> {

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

AnotherMadeUpAppDelegate.m

#import "AnotherMadeUpAppDelegate.h"

@implementation AnotherMadeUpAppDelegate


@synthesize window=_window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    UIViewController *vc1 = [[UIViewController alloc] init];
    UIViewController *vc2 = [[UIViewController alloc] init];
    AnotherMadeUpViewController *vc3 = [[AnotherMadeUpViewController alloc] init];

    UITabBarController *tbc = [[UITabBarController alloc] init];
    tbc.viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil];
    [vc1 release];
    [vc2 release];
    [vc3 release];

    [self.window addSubview:tbc.view];
    [self.window makeKeyAndVisible];
    return YES;
}
...
@end

AnotherMadeUpViewController.h

#import <UIKit/UIKit.h>

@interface AnotherMadeUpViewController : UIViewController<UIScrollViewDelegate>
{

    IBOutlet UIPageControl *pageControl;
    IBOutlet UIScrollView *scroller;
    IBOutlet UILabel *label;
}

@property (nonatomic,retain)IBOutlet UIPageControl *pageControl;
@property (nonatomic,retain)IBOutlet UIScrollView *scroller;
@property (nonatomic,retain)IBOutlet UILabel *label;

-(IBAction)clickPageControl:(id)sender;

@end

AnotherMadeUpViewController.m

#import "AnotherMadeUpViewController.h"

@implementation AnotherMadeUpViewController
@synthesize pageControl,scroller,label;

-(IBAction)clickPageControl:(id)sender
{
    int page=pageControl.currentPage;
    CGRect frame=scroller.frame;
    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0;
    [scroller scrollRectToVisible:frame animated:YES];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int page = scrollView.contentOffset.x/scrollView.frame.size.width;
    pageControl.currentPage=page;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
    [label release];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    scroller.pagingEnabled=YES;
    CGFloat labelOriginX = label.frame.origin.x;
    CGFloat labelOriginY = label.frame.origin.y;
    CGFloat scrollWidth = 0;
    int pageNumber = 0;
    for (int i=0; i<9; i++)
    {
        CGRect rect = label.frame;
        rect.size.height = label.frame.size.height;
        rect.size.width = label.frame.size.width;
        rect.origin.x = labelOriginX + scrollWidth;
        rect.origin.y = labelOriginY;
        label.frame = rect;
        label.text = [NSString stringWithFormat:@"%d", pageNumber];
        label.textColor = [UIColor redColor];
        [scroller addSubview:label];
        pageNumber++;
        scrollWidth += scroller.frame.size.width;
    }
    scroller.delegate=self;
    scroller.directionalLockEnabled=YES;
    scroller.showsHorizontalScrollIndicator=NO;
    scroller.showsVerticalScrollIndicator=NO;
    pageControl.numberOfPages=9;
    pageControl.currentPage=0;
    scroller.contentSize=CGSizeMake(pageControl.numberOfPages*self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:scroller];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    [label release];
    self.label = nil;
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Ответы [ 2 ]

0 голосов
/ 25 июня 2011

Проблема с этой строкой

AnotherMadeUpViewController *vc3 = [[AnotherMadeUpViewController alloc] init];

Вам нужно изменить ее на

AnotherMadeUpViewController *vc3 = [[AnotherMadeUpViewController alloc] initWithNibName:@"AnotherMadeUpViewController" bundle:nil];

Тогда ваш .xib загрузится и ваши розетки будут подключены.

И не забудьте подключить свои розетки к владельцу Файла в IB.

0 голосов
/ 25 июня 2011

Рассечение вашего viewDidLoad -

scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];

Вы, похоже, создаете новый экземпляр представления прокрутки здесь, но вы объявили его как выход .Если у вас нет розетки, удалите тег IBOutlet для scroller.Если он у вас есть и вы хотите его использовать, удалите приведенную выше строку.Более короткий способ сделать это:

scroller = [[UIScrollView alloc] initWithFrame:self.view.bounds];

Другое дело, что вы создаете 10 меток, но не назначаете рамку .Чтобы показать одну из них на каждой странице,

int pageNumber = 0;
for (int i = 0; i < 10; i++)
{
    UILabel *label = [[UILabel alloc] init];
    [label sizeToFit];
    label.center = CGPointMake (((2 * i + 1) * self.view.frame.size.width) / 2, self.view.frame.size.height / 2);
    label.text = [NSString stringWithFormat:@"%d", pageNumber];

    [scroller addSubview:label];
    [label release];

    pageNumber++;
}

и позже установите contentSize для отображения 10 страниц,

scroller.contentSize = CGSizeMake(10 * self.view.frame.size.width, self.view.frame.size.height);    
...