아래 코드를 사용하여 popover를 tableview와 함께 표시하면 완벽하게 작동합니다.popover의 테이블 뷰가 스크롤되지 않습니다.
tableview는 13 개의 숫자를 표시하며 스크롤하고 볼 수 있지만 시뮬레이터에서 마우스를 놓으면 맨 위로 돌아갑니다.
표시되는 행에 머물러 있지 않지만 1에서 10 번째 행으로 이동합니다.
스크롤 한 후 어떻게 위치에 유지합니까? 또는 아래 코드의 수정.
미리 감사드립니다.
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 680)];
UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320,680)]];
내가 그런
UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320,320)]];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
를 사용하지만 아래로 스크롤 할 때오고 유지하는 경우 :
- (IBAction)btn:(id)sender {
if([popoverController isPopoverVisible])
{
[popoverController dismissPopoverAnimated:YES];
return;
}
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 680)];
popoverView.backgroundColor = [UIColor blackColor];
numbers = [[NSMutableArray alloc] initWithObjects:@"1",@"2", @"3",@"4",@"5", @"6",@"7", @"8", @"9",@"10",@"11", @"12",@"13",nil];
UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 680)];
tblViewMenu.delegate = self;
tblViewMenu.dataSource = self;
tblViewMenu.rowHeight = 32;
[popoverView addSubview:tblViewMenu];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 320);
popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:self.btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [numbers count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
// Configure the cell...
NSString *color = [numbers objectAtIndex:indexPath.row];
cell.textLabel.text = color;
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *number = [numbers objectAtIndex:indexPath.row];
NSLog(@"%@",number);
[popoverController dismissPopoverAnimated:YES];
}
은 내가 아래의 값을 변경해야 추측 상단 행에. 그것은 스크롤되는 동일한 행.
변경 popoverContent.contentSizeForViewInPopover = CGSizeMake (320, 680); – NANNAV
그러나 그것은 단지보기를 확대 할 것이지만 50 행이 있다면 위의 수정은 작동하지 않을 것입니다. 나는 그 행에 머물고 싶습니다. 어떻게하면됩니까? 다시 한번 감사드립니다. –
기본적으로 테이블 뷰에는 스크롤이 없습니다. –