小编Bal*_*ram的帖子

没有任何按钮的UIAlertView

我想知道以下代码是否正确。我试图从“ timedAlert”方法中删除2秒钟后(并且没有在alertView中的任何按钮)自动关闭alertView。

    //this is in another method  
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Login successful." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [alert show];
    [alert release];
    [self timedAlert];
}

-(void)timedAlert
{
    [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:2];
}

-(void)dismissAlert:(UIAlertView *) alertView
{
    [alertView dismissWithClickedButtonIndex:nil animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

如果将alertView的cancelButton设置为“ nil”,那么“ [alertView dismissWithClickedButtonIndex:0动画:是];”将如何处理?事情工作???我试着将cancelButton设为“ nil”,并且可以正常工作,但无法弄清楚如何...。

PS:我从另一个调用timedAlert方法

任何帮助表示赞赏!谢谢!

iphone objective-c uialertview

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

方法"shouldChangeTextInRange"和"stringByReplacingCharactersInRange"如何工作?

我想知道以下代码的工作原理.

- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    return !([newString length] > 10);
}
Run Code Online (Sandbox Code Playgroud)

"stringByReplacingCharactersInRange"有什么作用?以上方法如何限制可以在textField中输入的字符数?

提前致谢!

objective-c textfield nsstring ios

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

在.h文件和.m文件中声明方法之间的区别,指定@interface和@end

我只是不明白为什么有些人在.m文件中声明方法.这些声明不能只是进入.h文件吗?这是我看到的主要内容:

//myClass.h

#import <UIKit/UIKit.h>

@interface myClass: UIViewController
{

}

@end
Run Code Online (Sandbox Code Playgroud)

和实现(.m)部分:

//myClass.m

#import "myClass.h"

@interface myClass

//declare some methods here

@end

@implementation myClass

//the actual implementation

@end
Run Code Online (Sandbox Code Playgroud)

当方法以这种方式声明时有什么区别吗?另外,"@private"方法可以在myClass.h中声明,不是吗?

iphone objective-c

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

标签 统计

objective-c ×3

iphone ×2

ios ×1

nsstring ×1

textfield ×1

uialertview ×1