0

我正在使用 Xcode 3.2.3。现在我正在做简单的 UITable 视图。为此我参考了这个链接

我已经完成了那里提到的所有步骤。但是当我的应用程序启动时,它只显示白屏。没有任何表格视图。请给我解决方案。提前致谢。

MyCode 是 AppDelegate.h

#import <UIKit/UIKit.h>

@class TableBasicsViewController;

@interface TableBasicsAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    TableBasicsViewController *viewController;
}

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

@end

AppDelegate.m

#import "AppDelegate.h"
#import "TableBasicsViewController.h"

@implementation TableBasicsAppDelegate

@synthesize window;
@synthesize viewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:        (NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

}


- (void)applicationWillTerminate:(UIApplication *)application {

}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {

}


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


@end

TableBasicViewController.h

#import <UIKit/UIKit.h>

@interface TableBasicsViewController : UIViewController <UITableViewDataSource,     UITableViewDelegate> {

}

@property (nonatomic, retain) NSArray *games;

@end

TableBasicViewController.m

#import "TableBasicsViewController.h"

@implementation TableBasicsViewController

@synthesize games;




/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from     a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    self.games = [NSArray arrayWithObjects: @"Super Mario Bros.",  
                  @"The Legend of Zelda", @"Blades of Steel", 
              @"Teenage Mutant Ninja Turtles", @"Excitebike",
              @"Dr. Mario", @"Duck Hunt", @"Tetris", @"Ice Climber",
              @"River City Ransom", @"Ninja Gaiden", @"Super Mario     Bros. 3",
              @"Mega Man 2", @"Kid Icarus", @"Metroid", @"Metal Gear",
              @"Super Mario Bros. 2", @"Zelda II: The Adventure of     Link",
              nil]; 
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:  (NSInteger)section {
     return [self.games count]; 
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Default";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                        reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.
    cell.textLabel.text = [self.games objectAtIndex:indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"Selected: '%@'", [self.games objectAtIndex:indexPath.row]);

}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:  (UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (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.
}

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


    - (void)dealloc {
        self.games = nil;
        [super dealloc];
    }

    @end
4

2 回答 2

1

请检查这个

TableBasicViewController.h

@interface TableBasicsViewController : UIViewController <UITableViewDataSource,     UITableViewDelegate> {

    IBOutlet UITableView *tableView;

}

@property (nonatomic, retain) NSArray *games;

@end

并将其链接到您的 xib 中

于 2012-10-16T05:09:18.503 回答
0

在您的 AppDelegate.m 文件中编写此代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:        (NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    viewController = [[TableBasicsViewController alloc]initWithNibName:@"TableBasicsViewController"];
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}
于 2012-10-16T05:01:38.900 回答