use*_*751 0 objective-c uitableview uitextview ios uitextfielddelegate
我想UITableView在点击时显示UITextView.键盘不应该显示.问题在于点击UITextView两者UITableView和键盘都显示出来.我只希望显示表格视图.我想显示从Web服务获取的数据,UITextView这是不可编辑的.按下导航栏中的编辑按钮,点击时UITextView,UITableView应该弹出而不是键盘.
我的代码如下:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
-(void)textViewDidBeginEditing:(UITextView *)textView{
[self.view endEditing:YES];
tableVw=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
tableVw.dataSource=self;
tableVw.delegate=self;
[self.view addSubview:tableVw];
}
-(void)viewDidLoad{
[super viewDidLoad];
txtVwDescription=[[UITextView alloc]initWithFrame:CGRectMake(10, 270, 300,stringSize.height+10)];
txtVwDescription.backgroundColor=[UIColor clearColor];
txtVwDescription.layer.cornerRadius=5;
txtVwDescription.backgroundColor=[UIColor colorWithRed:0.662745 green:0.662745 blue:0.662745 alpha:0.3];
[txtVwDescription setFont:[UIFont systemFontOfSize:13.0]];
txtVwDescription.contentInset=UIEdgeInsetsMake(0, 0, 0, 0);
[txtVwDescription setUserInteractionEnabled:NO];
txtVwDescription.editable=NO;
txtVwDescription.delegate=self;
[self.view addSubview:txtVwDescription];
}
-(void)edit{
[txtVwDescription setUserInteractionEnabled:YES];
txtVwDescription.editable=NO;
[txtVwDescription resignFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)
您可以使用UITextViewDelegate的textViewShouldBeginEditing方法返回NO,并在那里显示UITableView.以这种方式不应该呈现键盘.
| 归档时间: |
|
| 查看次数: |
703 次 |
| 最近记录: |