开发者

iPad not showing programmatically-created UITable

开发者 https://www.devze.com 2023-03-13 16:05 出处:网络
I have an iPad app that is not showing a table created programmatically. Where is the error or what is lacking in my code?

I have an iPad app that is not showing a table created programmatically. Where is the error or what is lacking in my code?

ViewController.h

#import <UIKit/UIKit.h>

@interface deleteViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
    UITableView *listTable;
}

@property (nonatomic, retain) UITableView *listTable;
//@property (nonatomic, retain) IBOutlet UITableView *listTable;



@end

ViewController.m

#import "deleteViewController.h"


@implementation deleteViewController
@synthesize listTable;



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];


    listTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 200) style:UITableViewStylePlain]; //changed THANKS!!, 

    listTable.delegate = self;
    listTable.dataSource = self;
    //listTable.allowsSelection = TRUE;
    [listTable reloadData];

    //listTable.backgroundColor = [UIColor clearColor];
    [listTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:listTable];
}


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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return 4;
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDe开发者_JAVA百科fault reuseIdentifier:CellIdentifier] autorelease];    
    }

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

    return cell;
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
    [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 {
    [super dealloc];
}

@end

Doesn't the table have to show even with out data like an array to show? I had tested this with data from coredata and doesnt show it, so I did this bare-bones test first to show the uitable programmatically.


ended up following the apple documentation duhh

UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)

                                                      style:UITableViewStylePlain];

tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

tableView.delegate = self;

tableView.dataSource = self;

[tableView reloadData];


//self.view = tableView;

[self.view addSubview: tableView];

[tableView release];

and it shows fine !!, ;)


Have you tried adding a [[self view] setNeedsDisplay] at the end of your viewDidLoad after you add the subView?


Your frame looks way off. You are adding that view as a subview to self.view try just using those dimensions instead or simply CGRectMake(0,0,200,200) to see if something shows. If it does, then you've proven the current dimensions place it out of bounds and it's getting clipped.

0

精彩评论

暂无评论...
验证码 换一张
取 消