나는이 코드를 인터넷 어딘가에서 발견했다. 어디서나 내가 신용을 줄 것인지 확신하지 못한다. 그것은 완벽하게 작동하지만 (이것은 UITableViewController 서브 클래스에 있습니다). 그것은 컨트롤러의 너비를 테이블에 표시된 가장 넓은 줄보다 넓게 설정합니다 (내 경우에는 공개 표시기를위한 자리를 남겨 둡니다).
self = [super initWithStyle:style];
if (self)
{
sortOrders = @[@"Alphabetic",@"User-assigned",@"Randomized"];
selectedSortOrder = @"Alphabetic";
//
// compute the size of the popover based on maximum width and required height to accommodate all rows
//
int rowHeight = [self.tableView.delegate tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
int totalRowHeight = [sortOrders count] * rowHeight;
CGFloat maxWidth = 0.0f;
for (NSString *s in sortOrders)
{
CGSize labelSize = [s sizeWithFont:[UIFont systemFontOfSize:14.0f]];
if (labelSize.width > maxWidth)
maxWidth = labelSize.width;
}
self.contentSizeForViewInPopover = CGSizeMake(maxWidth+50.0f, totalRowHeight);
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}
return self;
}
덕분에, 잘 작동하는, 나는 또한 테이블의 크기를 변경하거나이 팝 오버가 – user1794349