小编wil*_*amb的帖子

在OCMock中为一个类的所有实例模拟一个方法

我想使用OCMock为类的所有实例模拟一个实例方法,但是我没有类的实例来覆盖它,而是在我正在测试的方法中创建它.

所以我的问题是:是否可以为类的所有实例重写此方法,或者我是否需要将该实例注入方法而不是在方法内创建它?

[[ClassThatHasTheInstanceMethodToOverride andCall:@selector(callThisMethodInstead) onObject:self] someInstanceMethod];
Run Code Online (Sandbox Code Playgroud)

unit-testing objective-c ocmock

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

删除导航按钮

嘿,我写了一个继承了一些功能的类(A),包括导航按钮的实现.A类同时具有查看和编辑模式,我只想在编辑模式下显示按钮.到目前为止,我无法删除此按钮,我真的不想创建另一个类只是为了编辑.

其他类也继承了这个功能,所以我真的不想弄乱父母.

我用来创建按钮的代码如下:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    
UIImage *buttonImage = [UIImage imageNamed:@"button.png"];

[button addTarget:self 
               action:@selector(buttonPressed:) 
     forControlEvents:UIControlEventTouchUpInside];

button.bounds = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setTitle:NSLocalizedString(@"BUTTON", @"") 
            forState:UIControlStateNormal];

LPRBSLabel *buttonLabel = [[LPRBSLabel alloc] initWithStyle:UICustomeButtonTitle];
[button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, -5.0, 0.0)];

button.titleLabel.font = buttonLabel.font;
[button setTitleColor:buttonLabel.textColor forState:UIControlStateNormal];
[buttonLabel release];

UIBarButtonItem *barLeftInfoButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barLeftInfoButton;
[barLeftInfoButton release];
Run Code Online (Sandbox Code Playgroud)

inheritance uibutton uinavigationitem ios

5
推荐指数
2
解决办法
9293
查看次数

对UIAlertView进行子类化

我试图继承UIAlertView以更好地处理我的应用程序中的错误状态.我遇到的问题是使用otherButtonTitles nil终止参数,当我创建我的子类时,它只是拾取列表中的第一个字符串而不是所有字符串

+ (ErrorAlertView *)displayErrorAlertViewWithTitle:(NSString *)title 
                                           message:(NSString *)message 
                                          delegate:(id<UIAlertViewDelegate>)delegate 
                                     errorDelegate:(id<ErrorAlertViewDelegate>)errorDelegate
                                 cancelButtonTitle:(NSString *)cancelButtonTitle 
                                        displayNow:(BOOL)displayNow
                                               tag:(NSUInteger)tag
                                 otherButtonTitles:(NSString *)otherButtonTitles, ...;

{

  ErrorAlertView *errorAlertView = [[ErrorAlertView alloc]  initWithTitle:title 
                                                                  message:message 
                                                                 delegate:delegate 
                                                        cancelButtonTitle:cancelButtonTitle 
                                                        otherButtonTitles:otherButtonTitles, nil];


  errorAlertView.errorDelegate = errorDelegate;
  errorAlertView.tag = tag;

  if (displayNow) {

    [errorAlertView show];

  }

  return [errorAlertView autorelease];


}
Run Code Online (Sandbox Code Playgroud)

如果我进行以下调用上面的方法:

[ErrorAlertView displayErrorAlertViewWithTitle:[self noInternetConnectionAlertViewTitle] 
                                           message:[self noInternetConnectionAlertViewMessage] 
                                          delegate:self 
                                     errorDelegate:errorDelegate 
                                 cancelButtonTitle:@"OK" 
                                        displayNow:YES 
                                               tag:ErrorAlertTagInternetConnectionError 
                                 @"Try again",@"Setting", nil];
Run Code Online (Sandbox Code Playgroud)

显示UIAlertView时只显示@"再试一次"按钮.

null objective-c subclassing uialertview ios

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