我有下面的代碼來顯示與tableview彈出窗口,它的作品完美。彈出窗口中的表視圖不滾動
tableview顯示13個數字,我可以滾動和看到相同的,但是當我在模擬器上釋放鼠標觸摸時,它會回到頂部。
它並不停留在顯示的行上,而是將我帶回到第1行到第10行。
如何讓它在滾動後保持在位置上。或在下面的代碼中的任何修復。
在此先感謝。
- (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];
}
我想我需要改變以下值:
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 680)];
UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320,680)]];
如果我使用
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
然後
UITableView *tblViewMenu = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320,320)]];
但是,當我向下滾動,它使未來到頂行。它不會停留在同一行正在滾動到。
change popoverContent.contentSizeForViewInPopover = CGSizeMake(320,680); – NANNAV
但是,這隻會放大視圖,但如果有50行,那麼上述修復不會工作。我只是希望它留在特定的行。我該怎麼做?再次感謝。 –
基本上在tableview中沒有滾動。 –