小编Ken*_*ker的帖子

屏幕外UITableViewCells(用于大小计算)不尊重大小类?

我在UITableView中使用自动布局和大小类,单元格根据其内容自行调整大小.为此,我使用的方法对于每种类型的单元格,您保留该单元格的屏幕外实例并使用systemLayoutSizeFittingSize它来确定正确的行高 - 此方法在此StackOverflow帖子其他地方进行了很好的解释.

这很有效,直到我开始使用大小类.具体来说,我在常规宽度布局中为文本的边距约束定义了不同的常量,因此iPad上的文本周围有更多的空白.这给了我以下结果.

之前和之后

似乎新的约束集合得到了尊重(存在更多的空白),但行高度计算仍然返回与不应用特定于大小类的约束的单元格相同的值.屏幕外单元格中的部分布局过程不考虑窗口的大小等级.

现在我想,这可能是因为离屏幕视图没有上海华盈或窗口,因此它不具有任何尺寸类性状是指在点systemLayoutSizeFittingSize调用时(即使它似乎使用的调整限制边距).我现在通过在创建UIWindow后添加屏幕外的大小调整单元作为子视图来解决这个问题,从而得到所需的结果:

固定

这是我在代码中所做的事情:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    let contentItem = content[indexPath.item]

    if let contentType = contentItem["type"] {
        // Get or create the cached layout cell for this cell type.
        if layoutCellCache.indexForKey(contentType) == nil {
            if let cellIdentifier = CellIdentifiers[contentType] {
                if var cachedLayoutCell = dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell {                        
                    UIApplication.sharedApplication().keyWindow?.addSubview(cachedLayoutCell)
                    cachedLayoutCell.hidden = true
                    layoutCellCache[contentType] = cachedLayoutCell
                }
            }
        }

        if …
Run Code Online (Sandbox Code Playgroud)

uikit ios autolayout size-classes

15
推荐指数
2
解决办法
3545
查看次数

Pythonic方法将字符串列表转换为字典,奇数索引字符串作为键,偶数索引字符串作为值?

我有一个从某处解析的字符串列表,格式如下:

[key1, value1, key2, value2, key3, value3, ...]
Run Code Online (Sandbox Code Playgroud)

我想基于这个列表创建一个字典,如下所示:

{key1:value1, key2:value2, key3:value3, ...}
Run Code Online (Sandbox Code Playgroud)

for具有索引偏移的普通循环可能会成功,但我想知道是否有Pythonic方法可以做到这一点.列表理解似乎很有趣,但我似乎无法找到如何将它们应用于这个特定问题.

有任何想法吗?

python list-comprehension

8
推荐指数
2
解决办法
5675
查看次数

Ember.js:在同一页面/路由中显示多个数据库支持的资源/模型?

我正在以预算经理的形式使用Ember编写一个小测试应用程序.我有一个Budget对象,它包含一般属性,如每月限制和描述.我还有一组Expense对象,其中包含名称,花费的金额等.两者都是使用Ember Data的REST适配器从服务器检索的.

HTML:

<body>
    <script type="text/x-handlebars" data-template-name="budget">
    <h2>{{name}} (€ {{amount}})</h2>
    </script>

    <script type="text/x-handlebars" data-template-name="expenses">
    <ul id="expense-list">
        {{#each model}}
            {{render "expense" this}}
        {{/each}}
</ul>
</script>

    <!-- expense template -->
    <script type="text/x-handlebars" id="expense">
        <li>
            <label>{{description}}</label>
            <label class="subtle">{{formatDate time}}</label>
            <label class="amount">{{amount}}</label>
        </li>
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

JavaScript:

window.App = Ember.Application.create();

App.ApplicationAdapter = DS.RESTAdapter.extend({
    host: 'http://localhost:5000',
    namespace: 'outthepocket/api'
});

// Model
App.Expense = DS.Model.extend({
    amount: DS.attr('number'),
    description: DS.attr('string'),
    time: DS.attr('date')
});

App.Budget = DS.Model.extend({
    name: DS.attr('string'),
    amount: DS.attr('number')
});

// Routes
App.Router.map( function() { …
Run Code Online (Sandbox Code Playgroud)

javascript ember.js

2
推荐指数
1
解决办法
1198
查看次数