hi guys,
in my game,i need a view like UIAlertview ,but i need put three uitextfiled on the alertview. so,first i add a view to the uialertview which can cover the whole alertview,then i add some uitextfiled on the view.but i can not get the focus of the uitextfiled, there is no reply for my click.
the code is below:
- (void)loadAlertView:(int)account
{
if (self) {
post = [[UIView alloc]initWithFrame:CGRectMake(0,-200, 300, 275)];
post.backgroundColor = [UIColor lightGrayColor];
[post.layer setCornerRadius: 10.0f];
[self addSubview:post];
[self setBackgroundColor: [UIColor clearColor]];
UILabel *accountLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 140, 30)];
accountLabel.text = @"帐号:";
accountLabel.backgroundColor = [UIColor clearColor];
accountLabel.textColor = [UIColor whiteColor];
[post addSubview:accountLabel];
[accountLabel release];
accountTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 240, 30)];
accountTextField.backgroundColor = [UIColor whiteColor];
accountTextField.text = [NSString stringWithFormat:@"%d",account];;
[post addSubview:accountTextField];
accountTextField.delegate =self;
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 90, 140, 20)];
titleLabel.text = @"标题:";
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textColor = [UIColor whiteColor];
[post addSubview:titleLabel];
[titleLabel release];
titleTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 110, 240, 30)];
titleTextField.backgroundColor = [UIColor whiteColor];
[post addSubview:titleTextField];
[titleTextField becomeFirstResponder];
//注意先add 在添加
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 140, 140, 20)];
contentLabel.text = @"内容:";
contentLabel.backgroundColor = [UIColor clearColor];
contentLabel.textColor = [UIColor whiteColor];
[post addSubview:contentLabel];
[contentLabel release];
contentTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 160, 240, 30)];
[post addSubview:contentTextField];
contentTextField.backgroundColor = [UIColor whiteColor];
UIButton *send = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[send setFrame:CGRectMake(25,210,80,30)];
[post addSubview:send];
send.backgroundColor = [UIColor clearColor];
[send setTitle:@"发送" forState:UIControlStateNormal];
[send addTarget:self action:@selector(sendButtonClick) forControlEvents:UIControlEventTouchUpInside];
UIButton *cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cancel setFrame:CGRectMake(150,210,80,30)];
[post addSubview:cancel];
cancel.backgroundColor = [UIColor clearColor];
[cancel setTitle:@"取消" forState:UIControlStateNormal];
[cancel addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self show];
}
}
can anybody help me? Thanks a lot