ios - Popover TableView 未显示选中标记 (iOS7.1)

标签 ios objective-c uitableview checkmark

我有一个按钮,单击该按钮会显示一个带有表格 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/

相关文章:

objective-c - 写入 Main Bundle 目录。允许吗?

objective-c - Xcode 链接 - 命令 Ld 失败,退出代码非零

ios - 分组部分不显示在表格 View 中

ios - ionic 框架iOS输入焦点问题

ios - 为什么我不能以这种方式将数据添加到 Firebase 中?

objective-c - 关闭 NSStatusItem 的自定义窗口

ios - 核心数据 fatal error : unexpectedly found nil while unwrapping an Optional value

iphone - 在 didSelectRowAtIndexPath 中以编程方式编辑 Controller 的标题

ios - 创建一个自定义的可滚动 Collection View ,模仿 Swift 中 UITableView 的行为

ios - 关于 iOS 应用程序图标,App Store 与 Ad Hoc 是什么意思?