简体   繁体   中英

UITableView not showing iPad running iOS 5

I am running across a weird problem that came up out of now where. I'm not sure if it is because I have not updated to Xcode 4.2.1 or if it is iOS 5.

I have an iPad application that runs on OS's 4.0 - 5.0.

I have a UITableView that is contained in a view being shown modally as a form sheet.

The table shows up fine running on 4.x but the table disappears when running on 5.0.

I know everyone has heard this a million times but it literarily was working fine yesterday, I didn't change anything, now it doesn't work. I have a working copy from yesterday that is installed on an extra iPad running iOS 5. Today it doesn't want to work.

Here is how I have it setup, maybe you can spot a problem.

  1. The UITableView is created in IB. The datasource and delegate ARE set.

  2. The view is being called like so:

 GuidedSearchPriceViewController *guide = [[GuidedSearchPriceViewController alloc] initWithNibName:@"GuidedSearchPriceViewController_iPad" bundle:nil]; UINavigationController *temp = [[UINavigationController alloc] initWithRootViewController:guide]; temp.modalPresentationStyle = UIModalPresentationFormSheet; [guide setModalDelegate:self]; [guide setAppDelegate:self.appDelegate]; temp.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:temp animated:YES]; 

In iOS 4.x we get this: iOS 4.x

But is iOS 5 we get this: iOS 5

The viewDidLoad method of the Price view is:

- (void)viewDidLoad
{

    [super viewDidLoad];

    //Tried for testing but still does nothing
    self.table.delegate = self;
    self.table.dataSource = self;

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Type" style:UIBarButtonItemStyleBordered target:self action:@selector(nextScreen)];
    addButton.enabled = NO;
    self.navigationItem.rightBarButtonItem = addButton;

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismiss)];

        self.navigationItem.leftBarButtonItem = cancel;
        self.navigationController.navigationBar.tintColor = [UIColor redColor];
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png", [[NSBundle mainBundle] bundlePath], RP_iPad_FormsheetBackground]]];

    } else
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png", [[NSBundle mainBundle] bundlePath], RP_BackgroundImage]]];

    // Make sure the background of the table is clear. I have also tried taking this out
    // to resolve the disappearing issue but it has no effect. 
    if ([self.table respondsToSelector:@selector(backgroundView)]) {
        [self.table setBackgroundView:nil];
        [self.table setBackgroundView:[[UIView alloc] init]];
        [self.table setBackgroundColor:UIColor.clearColor]; 
    }

    priceList = [[NSArray alloc] initWithObjects:@"$750", @"$1000", @"$1250", @"$1500", @"$1750", @"$2000", @"$2000 +", nil];

}

Thank you very much for any help, and as always thank you for your time.


ANSWER

I managed to figure out what the problem was but I am not sure why it is occurring. Maybe someone can shed some light on it.

I had to insert

[table reloadData];

at the end of -(void)viewDidLoad

I'm not sure why it has to be there in iOS 5 but not in iOS 4.x

If you are using a UITableViewController with your table view, “When the table view is about to appear the first time it's loaded, the table-view controller reloads the table view's data.”

“If you choose not to use UITableViewController for table-view management, you must replicate what this class gives you 'for free.'”

The sample code in the second link sends reloadData to the table after setting its delegate and data source. Perhaps in iOS 4, a table view automatically reloaded itself when loaded, and in iOS 5 it was changed to match the documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM