标签: coding-style

sencha touch ::将背景图像添加到Panel

我尝试将图像添加到面板的背景中.图像来自加载的数据.我尝试了以下代码,但没有用:

var topPanel = new Ext.Panel({
        flex:1,
        title:'topPanel',
        style:'style="background-image: url('+this.jsonData.picURL+');'

});
Run Code Online (Sandbox Code Playgroud)

当我创建一个列表时,它与'itemTpl'配合使用.

我也试过了

style:'background-image: url({picURL});'
Run Code Online (Sandbox Code Playgroud)

和...一起

store: {
            fields: ['firstName','lastName', 'picURL'],
            data: this.jsondData
        }
Run Code Online (Sandbox Code Playgroud)

但后来我收到了消息

[[object Object]]不是'Function.prototype.apply'的有效参数.

任何想法都可以帮助!日Thnx

coding-style background-image sencha-touch

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

这种编码风格有什么好处?

最近我遇到了这种Objective-C编码风格:

- (NSFetchedResultsController *)fetchedResultsController
{
    NSFetchRequest      *fetchRequest;
    NSEntityDescription *entity;
    NSSortDescriptor    *sortDescriptor;
    NSArray             *sortDescriptors;
    NSError             *error;

    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }

    entity = [NSEntityDescription entityForName:@"Deck" inManagedObjectContext:self.managedObjectContext];

    sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES];
    sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

    fetchRequest = [[NSFetchRequest alloc] init];

    [fetchRequest setEntity:entity];
    [fetchRequest setFetchBatchSize:20];
    [fetchRequest setSortDescriptors:sortDescriptors];

    _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
    _fetchedResultsController.delegate = self;

    error = nil;

    if (![self.fetchedResultsController performFetch:&error]) {
        DLog(@"Failed fetching decks: %@, %@", [error localizedDescription], [error userInfo]);
    }

    // …
Run Code Online (Sandbox Code Playgroud)

macos cocoa-touch coding-style objective-c ios

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

如果我的函数逻辑上只返回自然数,我应该使用uint吗?

让我们考虑一个函数来获取一个人的出生日期并返回他的年龄(整年).如果日期是将来它会引发异常.它应该返回什么类型 - uint或int?uint似乎是合乎逻辑的自然约束.或者使用更常见的int更好吗?

c# sql unsigned types coding-style

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

如何在android中按主题级联样式

基本上,我想有一个单一的布局,我可以skin在主题上有所不同.这个网站上的许多示例和条目似乎都围绕这个问题跳了一下,所以我不完全确定它可以做到.或者我只是不明白.

这是概念.

假设我的应用程序与运动相关......应用程序默认为'SportTheme'我想用户也要说他们想要'足球'或'棒球'主题,并且在指定<TextView>元素上,我想要文本(默认为'Sport')更改为'Football'或'Baseball',因为整体主题适用于activity

在strings.xml中

<string name="label_sport">Sport</string>
<string name="label_football">Football</string>
<string name="label_baseball">Baseball</string>
Run Code Online (Sandbox Code Playgroud)

在activityA.java中 - 这里重要的是为活动设置主题(或者应用程序也很好).

@Override
protected void onCreate(Bundle savedInstanceState)
{
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.layout_a);

    switch (user.ThemePreference)
    {
        case FOOTBALL_THEME:
            this.setTheme(R.style.FootballTheme);
            break;
        case BASEBALL_THEME:
            this.setTheme(R.style.BaseballTheme);
            break;
        default:
            this.setTheme(R.style.SportTheme);
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

在layout_a.xml中

...
<TextView
   android:id="@+id/tvSport"
   android:layout_height="wrap_content"
   android:layout_width="match_parent"
   android:text="@string/label_sport"
   android:style="@style/SportLabel"></TextView>
Run Code Online (Sandbox Code Playgroud)

我在主题/风格中做什么?像这样的东西?这里重要的是TextView中的文本.我将在整个应用程序中的几个不同活动中使用相同的textView.

<theme name="SportTheme" parent="android:Theme" />

<theme name="FootballTheme" parent="SportTheme">
   <item name="android:background">@color/brown</item>
</theme>

<theme name="BaseballTheme" parent="SportTheme">
   <item name="android:background">@color/green</item>
</theme>


<theme name="SportTheme.SportLabel">
   <item name="android:text">@string/label_sport</item>
</theme>

<theme name="FootballTheme.SportLabel">
   <item name="android:text">@string/label_football</item>
   <item …
Run Code Online (Sandbox Code Playgroud)

android text themes coding-style textview

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

在Mathematica中将对齐添加到Manipulate输出

考虑以下因素:

Manipulate[
           If[Intersection[Row1, Row2] == {}, 
              Style[Plus @@ {Plus @@ Row1, Plus @@ Row2}, Bold, 20],
              "Error"],
{{Row1, {1}}, {1, 2, 3, 4, 5}, ControlType -> TogglerBar},
{{Row2, {2}}, {1, 2, 3, 4, 5}, ControlType -> TogglerBar}
           ]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

- 我希望"3"能够居中,是否可能?

coding-style wolfram-mathematica alignment

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

Android XML属性样式

为什么一些属性,如android:layout_width放在一起用下划线?虽然例如android:textColor使用骆驼套管?

为什么不完全坚持一种风格(下划线或骆驼套管)?

android coding-style

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

java代码样式问题 - for循环

以下代码是否清晰易读?

public void createDatabase() throws SQLException, IOException {
    SQLiteDatabase database = dbStore.getDatabase();
    LineNumberReader scriptInputReader = new LineNumberReader(new InputStreamReader(getClass().getResourceAsStream(SCRIPT_CREATE)));
    for(String line; (line = scriptInputReader.readLine()) != null;) {
        database.execSQL(line);
    }
}
Run Code Online (Sandbox Code Playgroud)

我写了很多像上面那样的"for"循环.对我来说它看起来很清楚 - 它显示了循环中使用的临时变量("line"),限制了它的范围并指出循环结束时(当"readLine"返回"null"时).我想知道其他程序员是否会讨厌那些......

或者这个:

    SQLiteDatabase database = dbStore.getDatabase();
    Cursor cursor = database.query("PINS", new String [] {"ID", "X", "Y"}, null, null, null, null, "ID");
    if(cursor.moveToFirst()) {
        for(; !cursor.isAfterLast(); cursor.moveToNext()) {
            (...)
        }
    }
    cursor.close();
Run Code Online (Sandbox Code Playgroud)

像上面这样的东西只是"整洁"还是已经是Java难题?

java coding-style

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

你会推荐Todd Hoff的C++ Coding Standard吗?

你好

目前我正在寻找一个好的C++编码标准,我可以坚持下去.在互联网上,我可以找到很多编码标准.一些规则在大多数规则中很常见.但也存在差异.我找到了Todd Hoff的C++编码标准(http://www.maultech.com/chrislott/resources/cstyle/CppCodingStandard.html).我看了看,发现它真的很棒.他不仅给出了一些共同的规则,而且还详细介绍了这些规则.名称公约就是一个好例子.

我想知道,如果有人使用这个C++编码标准,他会建议使用它吗?

c++ coding-style

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

Java比较字符串

 /**
 * A method to compare Strings
 * @param arg1
 * @param arg2
 * @return 
 */
public boolean myQuickCompare(String arg1, String arg2) {
    boolean a = arg1.length() == arg2.length();
    if (a) {
        for (int b = 0; b > arg1.length(); b++) {
            if (arg1.charAt(b) != arg2.charAt(b)) {
                a = false;
            }
        }
    }
    return a;
}
Run Code Online (Sandbox Code Playgroud)

我知道for循环是错误的方式,b永远不会大于字符串的长度.你会如何纠正这个问题?

你会给a和b什么明智的变量名?

java string compare coding-style

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

使用if(0 == foo())而不是(foo()== 0)有什么好处?

我发现一些程序员想在比较器运算符中这样编码.我发现阅读起来比较困难......

if (0 == foo()){
    ....
}
Run Code Online (Sandbox Code Playgroud)

foo() == 0在可读性方面有什么不同吗?使用0 == foo()有什么好处?

c++ java coding-style

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