我有一个按钮,单击该按钮会显示一个带有表格 View 的弹出窗口,该表格 View 显示一些数据列表。
在选择 TableView 行时,我想在单元格的右侧显示复选标记,但代码不起作用。有人可以帮我诊断一下吗?
如果我只使用普通的 TableView 而不是弹出 TableView ,相同的代码可以正常工作。
目前我正在使用 XCode 5.1.1 、 iOS7.1 、 iPad 模拟器。
//@property (assign,nonatomic)int selectedIndex;
//@property (strong,nonatomic)NSMutableArray *listArray;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.listArray=[[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.listArray count];
}
- (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 cell now
cell.textLabel.text = [self.listArray objectAtIndex:indexPath.row];
if(indexPath.row == self.selectedIndex)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedIndex = indexPath.row;
[tableView reloadData];
}
//For Button Action Method
- (IBAction)buttonAction:(id)sender {
UIButton *button = (UIButton*)sender;
TableViewController *tableViewController = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];
self.popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
[self.popover presentPopoverFromRect:[sender bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
最佳答案
代码没有错。您的 popoverview 不够大,无法覆盖 tableview 的右边界。使您的表格 View 的框架正确,您会找到复选标记。
关于ios - Popover TableView 未显示选中标记 (iOS7.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23423108/