runway20 / PopoverView

A simple UIView popover control for iPhone/iPad written in CoreGraphics.
1.02k stars 213 forks source link

Inserting a TableView from a xib file #5

Closed aleufms closed 12 years ago

aleufms commented 12 years ago

I found a bug when we try inserting a UITableView from a nib file. I tried to do this:

[[NSBundle mainBundle] loadNibNamed:@"MyTableViewNib" owner:self options:nil]; //My .xib file with UITableView inside it UITableView *myTableView = [nibs objectAtIndex:0]; //Assuming the tableview is the unique object from the nib [PopoverView showPopoverAtPoint:CGPointMake(0, 0) inView:self.view withTitle:nil withContentView:myTableView delegate:nil]

The size of the table doubles for unknown reason. The size of container is right.

Screenshot: http://img.photobucket.com/albums/v502/alessandro_ufms/Popoverbug.png

ocrickard commented 12 years ago

Hello,

I have just tried what you report as a bug, but can't seem to reproduce the sizing issue you're having. Here's a bit of code for what I'm using in the demo project.

In - (void)tapped:

UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
tableView.delegate = self;
tableView.dataSource = self;
[PopoverView showPopoverAtPoint:point inView:self.view withContentView:tableView delegate:self];

Then we add some of the datasource/delegate methods:

#pragma mark - UITableView Delegate Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.textLabel.text = @"text";

    return [cell autorelease];
}

And we make sure we conform to the UITableViewDataSource and UITableViewDelegate protocols in the header:

@interface ViewController : UIViewController <PopoverViewDelegate, UITableViewDataSource, UITableViewDelegate>

The size appears just fine, and responds well to touch input. If you would like further help, please post the actual xib you're using, and any other significant code that is being used.

Oliver

ocrickard commented 12 years ago

I have added a UITableView in the demo project as an example. I believe this may have been a problem in some other code, not in the PopoverView. Of course, I may be completely wrong. I am closing this issue for now.

capriele commented 11 years ago

I solved the problem in this way: 1) made the UITableView as subview of an UIView 2) all is done :D