走过海棠暮

文章 评论 浏览 25

走过海棠暮 2024-09-07 01:21:22

我这样使用,并且有效:(在 @interface 之外的 .h 中)

static NSString * const mkLocaleIdentifierUS = @"en_US";
static NSString * const mkLocaleUserSystemSettings = nil;

I use like this, and works: (in a .h outside @interface)

static NSString * const mkLocaleIdentifierUS = @"en_US";
static NSString * const mkLocaleUserSystemSettings = nil;

#import 仍然得到“重复符号”错误

走过海棠暮 2024-09-07 00:43:38

经过一段时间的研究后,我偶然发现了这个调试技巧。它显示 AVAudioPlayer 第二次被释放,导致崩溃。那么代表一定已经完成了清理工作吗?我检查了这个 SO 线程,它是建议代表不要取消分配。但是,如果我删除该行

   [newPlayer release]; 

“我的程序可以运行”!阅读此 SO 线程后,我相信我的问题是我应该实现 AVAudioPlayerDelegate 的 - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player success:(BOOL)flag 方法并在声音播放完毕后释放音频播放器。我是为 AVAudioRecorder 做的。

After working on it for a while I stumbled on this debugging tip. It showed me that AVAudioPlayer was deallocated the second time around, causing the crash. So the Delegate must have done the clean up? I checked this SO thread and it is suggestion that the Delegate does not deallocate. However, if I remove the line

   [newPlayer release]; 

My program works! After reading this SO thread, I believe my issue is that I should implement AVAudioPlayerDelegate's - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag method and release the audio player there, after the sound is done playing. I had done it for AVAudioRecorder.

从 AVAudioRecorder 播放后 AVAudioPlayer 崩溃

走过海棠暮 2024-09-07 00:29:58

我发现“:hover”在 iPhone/iPad Safari 中是不可预测的。有时点击元素会使该元素“:悬停”,而有时它会漂移到其他元素。

目前,我只在身体上上“无接触”课程。

<body class="yui3-skin-sam no-touch">
   ...
</body>

并将所有 CSS 规则与“:hover”放在“.no-touch”下面:

.no-touch my:hover{
   color: red;
}

在页面的某个位置,我有 javascript 从正文中删除 no-touch 类。

if ('ontouchstart' in document) {
    Y.one('body').removeClass('no-touch');
}

这看起来并不完美,但无论如何它都有效。

I found that ":hover" is unpredictable in iPhone/iPad Safari. Sometimes tap on element make that element ":hover", while sometimes it drifts to other elements.

For the time being, I just have a "no-touch" class at body.

<body class="yui3-skin-sam no-touch">
   ...
</body>

And have all CSS rules with ":hover" below ".no-touch":

.no-touch my:hover{
   color: red;
}

Somewhere in the page, I have javascript to remove no-touch class from body.

if ('ontouchstart' in document) {
    Y.one('body').removeClass('no-touch');
}

This doesn't look perfect, but it works anyway.

是否可以强制忽略 iPhone/iPad 用户的 :hover 伪类?

走过海棠暮 2024-09-06 23:43:04

编辑:删除了以前的答案,因为 MS 不推荐它。

本文讨论如何使用 WebBrowser 控件打开 OFfice 文档

http://support.microsoft.com/ KB/304643/

Edit: Removed previous answer since it's not recommended by MS.

This article talks about using the WebBrowser control to open OFfice documents instead

http://support.microsoft.com/kb/304643/

我想在表单上预览 Word 文档

走过海棠暮 2024-09-06 15:02:49

必须像下面这样;

[Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Required")]

must be like below ;

[Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Required")]

ASP.NET MVC 2 显示资源中的名称 DataAnnotation 不起作用

走过海棠暮 2024-09-06 12:20:16

原因是因为它是模糊的。编译器只需决定其中之一。有人认为间接性越少越好(性能可能是一个原因)。
如果开发人员只是写:

((Base)d).Foo (i);

它很清楚并且给你预期的结果。

The reason is because it is ambiguous. The compiler just has to decide for one. And somebody thought that the less indirect one would be better (performance might be a reason).
If the developer just wrote:

((Base)d).Foo (i);

it's clear and giving you the expected result.

方法重载解析和 Jon Skeet 的脑筋急转弯

走过海棠暮 2024-09-06 09:22:25

可以调试集成/功能测试。请参阅以下资源:

以防万一(以及其他读者),维基页面 处理基于 Eclipse 的 IDE 解释了如何远程调试外部 Maven 进程(不知道为什么你想避免这种情况)。

It is possible to debug integration/functional tests. See the following resources:

Just in case (and for other readers), the wiki page Dealing with Eclipse-based IDE explains how to remote debug an external Maven process (not sure why you want to avoid this).

在 Eclipse 中调试我的 Maven2 插件

走过海棠暮 2024-09-06 09:16:02

一种可能适合您的解决方案是不使用 T extends Number ,而是使用 T extends Number & 。可比较。此类型意味着:“T 只能设置为实现两个接口的类型。”

这使您可以编写适用于所有可比较数字的代码。静态类型且优雅。

这与 BennyBoy 提出的解决方案相同,但它适用于各种方法,而不仅仅是比较器类。

public static <T extends Number & Comparable<T>> void compfunc(T n1, T n2) {
    if (n1.compareTo(n2) > 0) System.out.println("n1 is bigger");
}

public void test() {
    compfunc(2, 1); // Works with Integer.
    compfunc(2.0, 1.0); // And all other types that are subtypes of both Number and Comparable.
    compfunc(2, 1.0); // Compilation error! Different types.
    compfunc(new AtomicInteger(1), new AtomicInteger(2)); // Compilation error! Not subtype of Comparable
}

One solution that might work for you is to work not with T extends Number but with T extends Number & Comparable. This type means: "T can only be set to types that implements both the interfaces."

That allows you to write code that works with all comparable numbers. Statically typed and elegant.

This is the same solution that BennyBoy proposes, but it works with all kinds of methods, not only with comparator classes.

public static <T extends Number & Comparable<T>> void compfunc(T n1, T n2) {
    if (n1.compareTo(n2) > 0) System.out.println("n1 is bigger");
}

public void test() {
    compfunc(2, 1); // Works with Integer.
    compfunc(2.0, 1.0); // And all other types that are subtypes of both Number and Comparable.
    compfunc(2, 1.0); // Compilation error! Different types.
    compfunc(new AtomicInteger(1), new AtomicInteger(2)); // Compilation error! Not subtype of Comparable
}

比较两个通用数字的值

走过海棠暮 2024-09-06 09:06:46

1) 按照惯例,将类的属性声明放在​​构造函数和方法之前。

2) CarLoan 类中的语句 this.client = client; 会出现编译错误,因为 client 字段在Loan 类。 (无论如何,该语句是多余的,因为您只是使用 setter 初始化了相同的字段......尽管希望您已经知道这一点。)

3)初始化超类字段的更好方法是将参数传递给超类构造函数。例如:

public abstract class Loan
{   
    private Person client;
    private double interestRate;

    public Loan(Person client, double interestRate) {
        this.client = client;
        this.interestRate = interestRate;
    }
    ...
}

public class CarLoan extends Loan
{   
    ...

    public CarLoan(Person client, double vehiclePrice, double downPayment, double salesTax,
                    double interestRate, CAR_LOAN_TERMS length)
    {
        super(client, interestRate); 
        this.vehiclePrice = vehiclePrice;
        ...
    }
}

这种方法更好的原因是 Loan 类负责其初始化,并且不依赖于各种子类构造函数来完成这项工作。 (如果您向 Loan 添加额外的字段,并将相应的参数添加到 Loan 构造函数中,编译器会提醒您修改所有子类构造函数以提供初始值super 构造函数链接。如果子类负责在初始化期间设置基类中的字段,则编译器不会注意到您忘记添加新的 setter 调用。)

4) 如果您这样做在构造函数中调用方法时,最好确保它们不能在子类中被重写。 (不……重写方法并非完全错误,但有些事情可能会出现严重错误。在构造函数中调用可能可重写的方法会使您的代码变得脆弱。)

5) 如果这是生产代码,请使用floatdouble 来表示货币值将是一个很大的禁忌!

1) It is conventional to put the declarations of the attributes of a class before the constructors and methods.

2) The statement this.client = client; in the CarLoan class will give you a compilation error because the client field is declared as private in the Loan class. (And that statement is redundant anyway because you just initialized the same field using the setter ... though expect you already knew that.)

3) A better way to initialize the fields of a superclass is to pass the arguments to the superclass constructor. For example:

public abstract class Loan
{   
    private Person client;
    private double interestRate;

    public Loan(Person client, double interestRate) {
        this.client = client;
        this.interestRate = interestRate;
    }
    ...
}

public class CarLoan extends Loan
{   
    ...

    public CarLoan(Person client, double vehiclePrice, double downPayment, double salesTax,
                    double interestRate, CAR_LOAN_TERMS length)
    {
        super(client, interestRate); 
        this.vehiclePrice = vehiclePrice;
        ...
    }
}

The reason this approach is better is that the Loan class takes responsibility for its initialization, and doesn't rely on the various subclass constructors doing the job. (If you add an extra field to Loan and add the corresponding parameter to the Loan constructor, the compiler reminds you to modify all of the subclass constructors to provide the initial value in the super constructor chaining. If the subclasses are responsible for setting fields in the base class during initialization, then the compiler won't notice that you forgot to add the new setter call.)

4) If you do call methods in a constructor, it is good practice to ensure that they cannot be overridden in a subclass. (No ... it is not entirely wrong for the methods to be overridden, but there are things that can go horribly wrong. Calling potentially overridable methods in a constructor makes your code fragile.)

5) If this was production code, use of float or double to represent currency values would be a big no-no!

Getter/Setter(组合、Java、HW)

走过海棠暮 2024-09-06 07:47:04

您的代码包含一个私有静态初始化实例:

private static Foo instance = new Foo();

您是否假设这意味着实例构造函数将始终在访问任何静态方法之前运行,从而确保bar已初始化?

在单线程的情况下,我认为你是对的。

事件顺序为:

  1. 调用 Foo.BarLength()
  2. Foo 的静态初始化(如果尚未完成)
  3. 私有静态成员 instance< 的静态初始化/code> 与 Foo 实例
  4. 进入 Foo.BarLength()

但是,每个应用程序域仅触发类的静态初始化一次 - 并且 IIRC 不会阻塞确保在调用任何其他静态方法之前它已完成。

因此,您可能会遇到以下情况:

  1. Thread Alpha:调用 Foo.BarLength()
  2. Thread Alpha:类 Foo 的静态初始化(如果尚未完成)开始
  3. 上下文切换
  4. 线程 Beta:调用 Foo.BarLength()
  5. 线程 Beta:不调用Foo 的静态初始化,因为那是已经进行
  6. 线程 Beta:进入 Foo.BarLength()
  7. 线程 Beta:访问 null 静态成员 instance

合约分析器无法知道您永远不会以多线程方式运行代码,因此必须谨慎行事。

Your code includes a private static initialized instance:

private static Foo instance = new Foo();

Are you assuming that this means the instance constructor will always have run before access to any static method, therefore ensuring bar has been initialized?

In the single threaded case, I think you're right.

The sequence of events would be:

  1. Call to Foo.BarLength()
  2. Static initialization of class Foo (if not already completed)
  3. Static initialization of private static member instance with instance of Foo
  4. Entry toFoo.BarLength()

However, static initialization of a class is only ever triggered once per App Domain - and IIRC there's no blocking to ensure it's completed before any other static methods are called.

So, you could have this scenario:

  1. Thread Alpha: Call to Foo.BarLength()
  2. Thread Alpha: Static initialization of class Foo (if not already completed) starts
  3. Context Switch
  4. Thread Beta: Call to Foo.BarLength()
  5. Thread Beta: No Call to static initialization of class Foo because that's already underway
  6. Thread Beta: Entry to Foo.BarLength()
  7. Thread Beta: Access to null static member instance

There's no way the Contracts analyser can know that you'd never run the code in a multithreaded way, so it has to err on the side of caution.

CodeContracts:可能在空引用上调用方法

走过海棠暮 2024-09-06 03:22:09

解决此问题的更好方法是使用 UIImage 方法 drawInRect: 来绘制图像。我假设您希望图像跨越您的视图的整个边界。这就是您在 drawRect: 方法中输入的内容。

而不是:

CGContextRef ctx = UIGraphicsGetCurrentContext();  
UIImage *myImage = [UIImage imageNamed:@"theImage.png"];  
CGImageRef img = [myImage CGImage];
CGRect bounds = [self bounds];
CGContextDrawImage(ctx, bounds, img);

写下:

UIImage *myImage = [UIImage imageNamed:@"theImage.png"];
CGRect bounds = [self bounds];
[myImage drawInRect:bounds];

The better answer to this problem is to use the UIImage method drawInRect: to draw your image. I'm assuming you want the image to span the entire bounds of your view. This is what you'd type in your drawRect: method.

Instead of:

CGContextRef ctx = UIGraphicsGetCurrentContext();  
UIImage *myImage = [UIImage imageNamed:@"theImage.png"];  
CGImageRef img = [myImage CGImage];
CGRect bounds = [self bounds];
CGContextDrawImage(ctx, bounds, img);

Write this:

UIImage *myImage = [UIImage imageNamed:@"theImage.png"];
CGRect bounds = [self bounds];
[myImage drawInRect:bounds];

如何补偿核心显卡坐标系翻转,方便绘图?

走过海棠暮 2024-09-06 02:02:24

Tabwidget 负责管理活动。所有未显示的活动都会暂停,并在 Tabhost 中选择活动时恢复。

The Tabwidget is responsible for managing the Activities. All Activities that are not shown are paused and are resumed at the moment the Activity is selected in the Tabhost.

TabWidget 活动处理 - 它每次都会创建一个新活动吗?

走过海棠暮 2024-09-05 23:48:38

问题是功能测试认为 mime_type 是“”(即空白)。因此,对我来说,一种更简单的方法是在 app.yml 中定义有效的文件类型:

all:
  .validation:
    valid_file_types:
      - text/comma-separated-values
      - text/csv
...et cetera...

test:
  .validation:
    valid_slug_file_types:
      -

然后在表单中,

$this->setValidator('file', new sfValidatorFile(array(
        'mime_types' => sfConfig::get('app_valid_file_types')
    )));

如果需要文件字段,则其他解决方案(sfBrowser 和 sfTestFunctional 上的额外方法)对我不起作用。

The problem is that the functional test thinks the mime_type is '' (i.e., blank). So for me an easier way was to define the valid file types in app.yml:

all:
  .validation:
    valid_file_types:
      - text/comma-separated-values
      - text/csv
...et cetera...

test:
  .validation:
    valid_slug_file_types:
      -

Then in the Form,

$this->setValidator('file', new sfValidatorFile(array(
        'mime_types' => sfConfig::get('app_valid_file_types')
    )));

The other solution (extra methods on the sfBrowser and sfTestFunctional) won't work for me if the file field is required.

symfony 中的文件上传功能测试,无需调用 click()

走过海棠暮 2024-09-05 20:24:23

随着 Safari 7 的发布,不仅第 3 方 cookie 被阻止。本地存储以及WebDB,任何类型的网站数据都被阻止。当您进入 Safari 首选项(CMD+逗号)时,在 Safari 7 上的隐私选项卡下,它现在显示:“阻止 cookie 和其他网站”,最初是“阻止 cookie”。这证实了这些变化。

其他浏览器将来可能会跟进。最有可能的是火狐。 Chrome,咳嗽*咳嗽*可能不会。

您可能必须采用一些解决方法,使用重定向技术或弹出窗口,类似于 disqus 所做的。

With the release of Safari 7, not only 3rd Party cookie is being blocked. Local Storage as well as WebDB, any kind of website data are being blocked. When you go to Safari Preferences (CMD+comma), Under privacy tab, on Safari 7, it now says : "Block cookies and other website", originally was "Block cookies". That confirms the changes.

Other browsers might follow through in the future. Most probably Firefox. Chrome, cough *cough* probably not.

You probably have to employ some workaround using redirection technique or popup similar to what disqus did.

Safari 会话变量中具有多个页面的 Facebook Iframe 应用程序不持久

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文