Ios UITextView抛出EXC\u错误\u访问
我已经创建了一个Ios UITextView抛出EXC\u错误\u访问,ios,ios7,uitextview,Ios,Ios7,Uitextview,我已经创建了一个UITextView实例,正在尝试设置其字体: UITextView *dummy = [[UITextView alloc] initWithFrame:self.frame]; dummy.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14];//self.font; 然而,在第二行,我得到了EXC\u BAD\u ACCESS错误,点击continue execution没有任何作用。它仍然永远挂在同一行上
UITextView
实例,正在尝试设置其字体:
UITextView *dummy = [[UITextView alloc] initWithFrame:self.frame];
dummy.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14];//self.font;
然而,在第二行,我得到了EXC\u BAD\u ACCESS
错误,点击continue execution没有任何作用。它仍然永远挂在同一行上,控制台上没有错误消息。它还用于抛出self.font
(我在工作UILabel
中使用代码,它的font
是有效的字体对象)。为什么我会犯这个错误
更新:我也尝试过setText:
它也会抛出相同的错误。我是否遗漏了一些明显的内容?请尝试以下代码
UITextView *textview =[[UITextView alloc]init];
textview.frame=CGRectMake(200, 10, 500, 50);
//To make the border look very close to a UITextField
[textview.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[textview.layer setBorderWidth:2.0];
textview.delegate=self;
//The rounded corner part, where you specify your view's corner radius:
textview.layer.cornerRadius = 5;
textview.clipsToBounds = YES;
[textview setFont:[UIFont fontWithName:@"Helvetica Neue" size:11]];
[textview setTextColor:[UIColor blueColor]];
[textview setReturnKeyType:UIReturnKeyDone];
我找到了解决办法
我尝试了
[[UITextView alloc]initWithFrame:self.frame textContainer:nil]
而不是[[UITextView alloc]initWithFrame:self.frame]代码>成功了。我不明白为什么另一种方法不起作用,即使我使用nil
作为textContainer
您是否尝试过:[dummy setFont:size:]代码>?@Lukasz'Severiaan'GrelaUITextView
没有setFont:size:
方法。它是真代码吗?(如果您将分配的UITextField设置为弱指针,则系统将释放它)@AndrewRomanov是的,从我的项目复制/粘贴。NSZombies说:“我想吃掉您的大脑”:)您是否尝试过,在第一个崩溃的代码中清理项目,然后再次安装?有时对我有用。@DavidBemerguy,我没有。但现在问题解决了。无论如何,谢谢你。这可能是指定初始值设定者的问题。