在纵向模式下,我的iPad的RootViewController表有一个空白的第一行,如果是行的话

时间:2011-02-27 06:11:56

标签: uitableview

我用两个plist文件中的静态文本填充两个NSArrays。这些是使用RootViewController的第一个UITableView的标题和副标题。在横向中,表格与顶部对齐,没有空行或空白区域。表格显示正常。

在纵向模式下,表格显示但是在单个表格行的厚度或高度附近有空白区域。我已经调试了,两个数组都有5个数。有空格(似乎是一行高)和显示屏中的5个单元格。如果我通过选择一个项目进行导航并返回,则空间消失了。

这是我的RootViewController。


    //
//  RootViewController.m
//  Punch
//
//  Created by David Whitehurst on 1/27/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"
#import "DetailViewController.h"
#import "ContextController.h"
#import "PunchAppDelegate.h"


@implementation RootViewController

@synthesize contextController,detailViewController,arrayData,subArrayData,imagesList;

- (void)configureView {
}

- (NSArray *) getImageArray {

    NSString *goalPath = [[NSBundle mainBundle] pathForResource:@"85-trophy@2x" ofType:@"png"];
    NSString *vitalPath = [[NSBundle mainBundle] pathForResource:@"77-ekg@2x" ofType:@"png"];
    NSString *medicinePath = [[NSBundle mainBundle] pathForResource:@"79-medical-bag@2x" ofType:@"png"];
    NSString *mealPath = [[NSBundle mainBundle] pathForResource:@"48-fork-and-knife@2x" ofType:@"png"];
    NSString *exercisePath = [[NSBundle mainBundle] pathForResource:@"63-runner@2x" ofType:@"png"];

    UIImage *goalPathRes = [UIImage imageWithContentsOfFile:goalPath];
    UIImage *vitalPathRes = [UIImage imageWithContentsOfFile:vitalPath];
    UIImage *medicinePathRes = [UIImage imageWithContentsOfFile:medicinePath];
    UIImage *mealPathRes = [UIImage imageWithContentsOfFile:mealPath];
    UIImage *exercisePathRes = [UIImage imageWithContentsOfFile:exercisePath];

    NSArray *array = [[NSArray alloc] initWithObjects:goalPathRes,vitalPathRes,medicinePathRes,mealPathRes,exercisePathRes,nil];

    return array;
}

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {

    NSString *dataFile = [[NSBundle mainBundle] pathForResource:@"array" ofType:@"plist"];
    NSString *dataFileSub = [[NSBundle mainBundle] pathForResource:@"subarray" ofType:@"plist"];

    imagesList = [self getImageArray];  

    if ([[NSFileManager defaultManager] fileExistsAtPath:dataFile]) {
        arrayData = [[NSArray alloc] initWithContentsOfFile:dataFile];
    } 

    if ([[NSFileManager defaultManager] fileExistsAtPath:dataFileSub]) {
        subArrayData = [[NSArray alloc ]initWithContentsOfFile:dataFileSub];
    } 

    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
    self.title = @"Punch";
    self.navigationController.navigationBar.barStyle = UIStatusBarStyleBlackOpaque;
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.navigationController.navigationBar.translucent = YES;
    //self.tableView
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // set first row selected
    NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionBottom];

}
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
*/

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

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

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

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }

    // Configure the cell.
    cell.textLabel.text = [arrayData objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [subArrayData objectAtIndex:indexPath.row];
    cell.imageView.image = [imagesList objectAtIndex:indexPath.row];
    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // The table view should not be re-orderable.
    return NO;
}


#pragma mark -
#pragma mark Table view delegate

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

    contextController = [[ContextController alloc] initWithNibName:@"ContextController" bundle:nil];
    PunchAppDelegate *delegate = (PunchAppDelegate *)[[UIApplication sharedApplication] delegate];

    if (0 == indexPath.row) {
        [delegate setContextKey:@"Goal"];
        [self.contextController setKey:@"Goal"];
        self.contextController.title = @"Goals";
    }

    if (1 == indexPath.row) {
        [delegate setContextKey:@"Food"];
        [self.contextController setKey:@"Food"];
        self.contextController.title = @"Food Log";
    }

    if (2 == indexPath.row) {
        [delegate setContextKey:@"Blood"];
        [self.contextController setKey:@"Blood"];
        self.contextController.title = @"Blood Sugar Log";
    }

    [self.navigationController pushViewController:contextController animated:YES];
    [contextController release];    

}

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     if (self) {
         // Custom initialization.
     }
     return self;
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}

- (void)dealloc {

    [contextController release];
    [arrayData release];
    [subArrayData release];
    [imagesList release];
    [super dealloc];
}

@end

请提供有关如何摆脱此空白或其原因的建议。

谢谢,

大卫

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。这是半透明的YES属性。我先将它改为NO,然后在顶部正确对齐。然后我评论了我认为的默认属性。


    //self.navigationController.navigationBar.barStyle = UIStatusBarStyleBlackOpaque;
    //self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    //self.navigationController.navigationBar.translucent = NO;