Построить успешно, но вывод не поступает в iOS Simulator - PullRequest
0 голосов
/ 08 июня 2011

Я хочу создать простое табличное представление со списком часовых поясов.Когда я пытался «построить и запустить» код, он сказал, что «сборка прошла успешно», но нет табличного представления со списком в качестве вывода симулятора iOS.Появляется только черный пустой экран.Я не мог понять, где я застрял.Поэтому, пожалуйста, помогите мне найти решение.

Коды следующие.

1.RootViewController.h

#import < UIKit/UIKit.h>

@interface RootViewController : UITableViewController {
    NSArray *timeZoneNames;
}

@property (nonatomic, retain) NSArray *timeZoneNames;

@end

2.RootViewController.m

#import "RootViewController.h"
#import "SimpleTableViewAppDelegate.h"

@implementation RootViewController

@synthesize timeZoneNames;

- (void)viewDidLoad {
     self.title = NSLocalizedString(@"Time Zones", @"Time Zones Title");
}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section       
{
    return [timeZoneNames count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) 
  indexPath {

    static NSString *MyIdentifier = @"MyIdentifier";

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

    // Configure the cell.
    NSString *timeZoneName = [timeZoneNames objectAtIndex:indexPath.row];
    cell.textLabel.text = timeZoneName;

    return cell;
}

//The Table view has only one section

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath  *) 
   indexPath {
    return nil;
}


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

@end

3 SimpleTableViewAppDelegate.h

import

@interface SimpleTableViewAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UINavigationController *navigationController;
}

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

@end

SimpleTableViewAppDelegate.m

#import "SimpleTableViewAppDelegate.h"   
#import "RootViewController.h"

@implementation SimpleTableViewAppDelegate

@synthesize window;
@synthesize navigationController;    

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

    RootViewController *rootViewController = [[RootViewController alloc] 
                                                   initWithStyle:UITableViewStylePlain];

    //Retrieve the array of known time zone names, then sort the array and pass it to the root  
        //view controller.

    NSArray *timeZones = [NSTimeZone knownTimeZoneNames];

    rootViewController.timeZoneNames = [timeZones sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

    UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

    self.navigationController = aNavigationController;    
    [aNavigationController release];

    [rootViewController release];

    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}

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

@end

1 Ответ

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

Хммм, может быть несколько причин, почему это происходит.Первое, что я хотел бы сделать, это проверить, является ли массив пустым, когда представление загружается для rootViewController.Если он пуст, он, вероятно, устанавливается после загрузки представления, и именно поэтому вы не видите никаких ячеек.Вы должны убедиться, что массив не пуст для rootViewController.Для этого вы можете просто напечатать счетчик для массива и посмотреть, сколько у него объектов.

В противном случае попробуйте добавить [tableView reloadData];либо внутри метода viewDidLoad для вашего rootViewController, либо в методе viewWillAppear в том же контроллере.

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