2014-11-01 69 views
1

我已經創建UITextView以編程方式,textview是根據需要創建的,但是當我嘗試使用標記應用程序崩潰時爲textview設置值。settext到uitextview應用程序崩潰 - ios sdk

我可以設置其他參數,如setUserInteractionEnabled沒有問題。

它的代碼如下..

創建的TextView使用標籤的TextView

UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0,0,100,200)]; 
    textView.font = [UIFont systemFontOfSize:30]; 
    //textView.font = [UIFont boldSystemFontOfSize:12]; 
    textView.backgroundColor = [UIColor grayColor]; 
    textView.tag=i; 
    [textView setTextAlignment:NSTextAlignmentCenter]; 
    textView.text=[NSString stringWithFormat:@"%d",i]; 
    textView.inputView= [LNNumberpad defaultLNNumberpad]; 
    textView.editable = YES; 
    [textView setDelegate:self]; 
    [self.view addSubview:textView]; 

量變到質變值..

UITextView *txtviewfound = (UITextView *)[self.view viewWithTag:j]; 
      [txtviewfound setText:@"some text"]; 
      [txtviewfound setUserInteractionEnabled:FALSE]; 

當我評論的setText喜歡它工作正常。

如果我缺少任何東西,請讓我知道。

在此先感謝

+1

我和j是什麼? – Balu 2014-11-01 10:48:24

+0

我和j有整數值,它的循環直到5 @Sunny – Satish 2014-11-01 10:49:40

回答

1

型鑄造之前,你需要檢查的天氣子視圖屬於 TextView的還是不行,因爲默認情況下爲0的標籤 值。如果您有任何其他對象中的每個對象你的看法然後它會創建 問題。

if([[self.view viewWithTag:i]isKindOfClass:[UITextView class]]) 
{ 
      UITextView *txtviewfound = (UITextView *)[self.view viewWithTag:j]; 
      [txtviewfound setText:@"some text"]; 
      [txtviewfound setUserInteractionEnabled:NO]; 

} 
+0

感謝@sunny你的時間...... :) – Satish 2014-11-01 11:00:54

0

什麼是崩潰日誌說?一個索引如果綁定可能? 另外可以肯定的是,不要將標籤設置爲像1到5這樣的非常低的數字,它們很少但仍然可以被蘋果公司採用。