【问题标题】:How to implement an editable UITableView, similar to Safari Bookmarks?如何实现一个可编辑的 UITableView,类似于 Safari 书签?
【发布时间】:2012-08-28 17:50:30
【问题描述】:

我正在尝试实现一个非常类似于 Mobile Safari 中的书签视图的列表。当您单击编辑时,您会得到以下信息:

在此屏幕中,您可以删除项目并更改其属性(通过右侧的 DisclosureIndicator)。我关注了 Xamarin 的 tutorial,但是当表格处于编辑模式时,我无法确切知道如何添加 DisclosureIndicator。我将在 ObjC 或 C# 中采用解决方案。

我在这里遗漏了一些简单的东西吗?

【问题讨论】:

    标签: c# ios uitableview xamarin.ios xamarin


    【解决方案1】:

    在 iOS 中,这是通过以下方法完成的:

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        return YES;
    }
    
    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
        return NO;
    }
    
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewCellEditingStyleDelete;
    }
    
    - (void) setEditing:(BOOL)editing animated:(BOOL)animated {
        [super setEditing: editing animated: animated];
        [self.tableView setEditing:editing animated:animated];
    }
    
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
        if (editingStyle == UITableViewCellEditingStyleDelete) {
                 //delete rows
        }
    }
    

    披露指示器是一个电池附件。可以在cellForRowAtIndexPath方法中设置。

    - (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] autorelease];
        }
    
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    }
    

    【讨论】:

    • 我可能遗漏了一些东西,但是当我将 UITableView 置于编辑模式时,DisclosureIndicator 消失了。
    【解决方案2】:

    使用

    cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
    

    在GetCell方法中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多