可扩展的UITableView动态

时间:2016-08-09 10:09:59

标签: ios swift uitableview

我正在使用This Example进行动态扩展单元格。此示例显示如何使用数据模型扩展单元格。但我需要的是,当一个单元格点击时,它会获取要扩展的记录数量。我试图做如下。但我不能达到我想要的。请有人帮助我。

这就是我如何动态地将样本数据添加到我的Datamodel。

df1[4:8] <- lapply(df1[4:8], na.aggregate, FUN = median)

这就是我获取tableview记录数的方法

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    DataModel.sampleDetails = ["Sample 1","sample 2","sample 3"]

    //historyTable.beginUpdates()

    switch expandedIndex {
    case .None:
        expandedIndex = NSIndexPath(forRow: indexPath.row + 1, inSection: indexPath.section)

    case .Some(let index) where index.row == indexPath.row:
        tableView.deselectRowAtIndexPath(indexPath, animated: false)

    case .Some(let index) where index.row == indexPath.row + 1:
        expandedIndex = nil
        tableView.deselectRowAtIndexPath(indexPath, animated: false)

    case .Some(let index) where index.row < indexPath.row:
        expandedIndex = nil
        self.tableView(tableView, didSelectRowAtIndexPath: NSIndexPath(forRow: max(0,indexPath.row - 1), inSection: indexPath.section))
    default:
        expandedIndex = nil
        expandedIndex = NSIndexPath(forRow: indexPath.row + 1, inSection: indexPath.section)
    }

    //historyTable.endUpdates()
}

仅当我更改下面的代码时才有效

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    let sample = !(DataModel.sampleDetails.isEmpty) ? DataModel.sampleDetails.count : 0

    return expandedIndex != nil ?
        viewModel.count() + sample :
        viewModel.count()
}

我不知道是什么问题。

请帮帮我

1 个答案:

答案 0 :(得分:1)

您已在didSelectRow上设置dataModel.sampleDetails。

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { }

但是

try {

        Properties prop = new Properties();
        prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
        prop.put(Context.SECURITY_AUTHENTICATION, "simple");
        prop.put(Context.SECURITY_PRINCIPAL,"sandeep.p");
        prop.put(Context.SECURITY_CREDENTIALS,"Password@12");
        prop.put(Context.PROVIDER_URL, "LDAP://10.141.144.5:389");

        try {
             LdapContext ctx1 =new InitialLdapContext(prop,null);

             String uname="sandeep.p";
             String oldPassword="Password@12";
             String newPassword="Password@123";
             String quotedPassword = "\"" + newPassword + "\""; 
             char unicodePwd[] = quotedPassword.toCharArray(); 
             byte pwdArray[] = new byte[unicodePwd.length * 2]; 
             for (int i=0; i<unicodePwd.length; i++) { 
             pwdArray[i*2 + 1] = (byte) (unicodePwd[i] >>> 8); 
             pwdArray[i*2 + 0] = (byte) (unicodePwd[i] & 0xff); 
             } 
             ModificationItem[] mods = new ModificationItem[1]; 
             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, 
             new BasicAttribute("UnicodePwd", pwdArray)); 
             System.out.println("connects");
             ctx1.modifyAttributes(uname, mods);
             System.out.println("changed");
        } catch (AuthenticationNotSupportedException ex) {
            /* Wrong SECURITY_AUTHENTICATION, it may be none, simple or Strong*/
            System.out.println("The authentication is not supported by the server "+ex);
        } catch (AuthenticationException ex) { 
            System.out.println(" server "+ex);
        } catch (NamingException ex) {
            System.out.println("error when trying to create the context "+ex);
        }
    } catch (Exception e) {
        System.out.println("Exception "+e);
    }
在设置DataModel.sampleDetails之前调用

。所以你应该把这一行放在viewDidLoad()上。这将解决您的问题

相关问题