【发布时间】:2011-04-14 13:10:53
【问题描述】:
我正在尝试执行以下操作
- (void)textViewDidChange:(UITextView *)textView{
if(textView == txtYourTip){
if([txtYourTip.text length] < 100){
strTip = txtYourTip.text;
NSLog(@"%@",strTip);
} else {
NSLog(@"%@",strTip);
txtYourTip.text = strTip;
}}
当控件转到其他部分时应用程序崩溃。 strTip 是 NSString 类型。
viewDidLoad 包含
txtYourTip = [[UITextView alloc] initWithFrame:CGRectMake(15, 80, 290, 80)];
[txtYourTip.layer setBorderColor:[[UIColor lightGrayColor] CGColor]];
[txtYourTip setDelegate:self];
[txtYourTip setContentInset:UIEdgeInsetsMake(10, 10, 10, 10)];
txtYourTip.layer.cornerRadius = 10.0;
[txtYourTip.layer setBorderWidth:2.0];
[contentView addSubview:txtYourTip];
strTip = [[NSMutableString alloc] init];
【问题讨论】:
-
strTip 和 txtYourTip 声明在哪里?你确定它们不是 nil 并且当你到达 else 时它们的指针是有效的吗?
-
两者都在 .h 文件中声明,并且我在 viewDidLoad 中设置了 strTip = @""
-
你能发布 viewDidLoad 的源代码吗?还是别的什么?
-
txtYourTip = [[UITextView alloc] initWithFrame:CGRectMake(15, 80, 290, 80)]; [txtYourTip.layer setBorderColor:[[UIColor lightGrayColor] CGColor]]; [txtYourTip setDelegate:self]; [txtYourTip setContentInset:UIEdgeInsetsMake(10, 10, 10, 10)]; txtYourTip.layer.cornerRadius = 10.0; [txtYourTip.layer setBorderWidth:2.0]; [contentView addSubview:txtYourTip]; strTip = [[NSMutableString alloc] init];
-
也许如果你添加整个班级......但如果你这样做,请更新你的问题 - 不要在 cmets 中添加它。
标签: objective-c nsstring uitextview