iphone - 如何显示在界面生成器中创建的自定义 uialertview

标签 iphone objective-c customization uialertview

我在 ib 中创建了一个自定义 uialertview,带有两个按钮和一个文本字段。 然后我以这种方式创建一个 .h 和一个 .m:

#import <UIKit/UIKit.h>

@interface DialogWelcome : UIAlertView{
    IBOutlet UITextField *text;
    UIButton *ok;
    UIButton *annulla;
}
@property(nonatomic,retain) UITextField *text;
- (IBAction)ok:(id)sender;
- (IBAction)annulla:(id)sender;
@end

和.m:

#import "DialogWelcome.h"

@implementation DialogWelcome
@synthesize text;

-(IBAction)ok:(id)sender{

}
-(IBAction)annulla:(id)sender{

}

@end

我还没有实现方法,因为首先我需要展示它! 我在 View Controller 中这样调用它:

- (void)viewDidLoad
{
    [super viewDidLoad];
    DialogWelcome *alert = [[DialogWelcome alloc] initWithTitle:@"Welcome" 
                                                message:nil 
                                               delegate:nil 
                                      cancelButtonTitle:nil 
                                      otherButtonTitles:nil];

    [alert show];
    dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*2.0);
    dispatch_after(delay, dispatch_get_main_queue(), ^{
        [alert dismissWithClickedButtonIndex:0 animated:YES];
    });

    [alert release];
}

这将显示一个带有标题的空普通 uialertview。为什么它不显示我的自定义 uialertview?

最佳答案

来自UIAlertView Class Reference :

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

因此,您尝试执行的操作是明确不允许的。

关于iphone - 如何显示在界面生成器中创建的自定义 uialertview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7871800/

相关文章:

iphone - 使后台线程等待直到另一个后台线程在iphone中完成

iphone - NSFileManager 不删除存在的文件

ios - 为 Framesetter 提供正确的行间距调整

qt - 如何创建类似 Material Design 的自定义元素?

c++ - 如何在 QML 中创建自定义基本类型?

xcode - 是否可以更改 Xcode 缩进注释 block 的方式?

html - iPhone CSS 视口(viewport)问题 - 网站 "wobbles"左/右

iphone - 如何控制 UIPickerView 组件的滚动?

ios - 更改 map 图钉(颜色或图像)

iphone - 如何通过 Objective-c 访问 iPhone 文件?