2012-05-02 6 views
2

アプリケーションを初めて起動したときにテキストフィールドを編集不可にしたいと考えています。 UIBarbuttonの項目をタップすると、編集可能なテキストフィールドになります。 私は以下のコードを試していますが、動作していません。アプリケーションの最初の起動時にテキストフィールドを編集できないようにする方法

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
if(edit == NO){ 
    textField.enabled = NO; 
} 
    if(edit == YES){ 
    textField.enabled = NO; 
    } 
return YES;} 

答えて

2

クリックバーボタンは、ボタンのClickメソッドでyesにそれを設定した後、あなたは、このメソッドに

-(Void)viewwillappers 
{ 
    [textfield setEnable:NO]; 
} 

を使用する必要があります。

+1

このメソッド[textfield setEnable:NO]; virendra要件に従ってviewdidLoadに配置する必要があります。 –

+0

あなたは正しいですが、もしvirendraが別のビューに移動して戻ってきて、同じことをしたい場合、vewdidloadは機能しません。 – vishiphone

+0

あなたは評判の矢で私にマイナスをタップしていますか? – vishiphone

0

シンプルです。

[textfield setEnable:NO]; 

Benifits:

すると再度読み込むとき

XIBで、textrFieldの性質のために、これを使用するバーボタンのクリックイベントに

.Nowを "有効なユーザーとの対話" をオフに最初に、textFieldは無効になります。

それはあなたが望むようにそうするでしょう。

0
- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *MyIdentifier = @"tblCellView"; 

PlayerDetailsCell *cell = (PlayerDetailsCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if(cell == nil) { 
    [[NSBundle mainBundle] loadNibNamed:@"PlayerDetailsCell" owner:self options:nil]; 
    cell = tblCell; 
} 
return cell; 
} 

あなたのテーブルビューの使用このコードを、あなたのUITableViewCell class.likeを呼び出して、私は(playerdetailscell)

+0

何回回答を投稿していますか? –

+0

彼は一度に複数の質問を持っているからです。 – vishiphone

+0

@anonymousもし間違っていたら、私は次回から気づくでしょう。 – vishiphone

2
txtfld.userInteractionEnabled = NO; 
// perform changes and enable afterwards 
txtfld.userInteractionEnabled = YES; 
+0

@virendra –

1
- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView 
         dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleValue1 
      reuseIdentifier:CellIdentifier] 
      autorelease]; 
} 
cell.textLabel.text=[Players objectAtIndex:indexPath.row]; 

playername=[[UITextField alloc]initWithFrame:CGRectMake(10, 3, 280, 30)]; 
[email protected]"Player"; 
playername.delegate=self; 
playername.keyboardType=UIKeyboardTypeDefault; 
// playername.returnKeyType=UIReturnKeyDone; 
[cell.contentView addSubview:playername]; 
return cell; 
} 

ダイナミックテキストフィールドのために使用これを呼び出しています。

+0

それは正常に動作していますが、まだテキストフィールドのやりとりを無効にすることはできません。 – iosDev

+0

なぜ1回以上回答を投稿していますか? –

+0

これは意味をなさない。 –

2

あなたは、このために- (void)viewWillAppear:(BOOL)animatedデリゲートを使用し

- (void)viewWillAppear:(BOOL)animated 
{ 
    [textfield setEnable:NO]; 
} 

そして、あなたが使用している場合

- (IBAction)clicked:(id)sender 
    { 
    [textfield setEnable:YES]; 
    } 

、バーボタンのクリックメソッドで[textfield setEnable:YES];を書くことができ、この

-(Void)viewwillapper 

{ 

[textfield setuserintractionEnable:yes]; 

} 
2

を試してみてください上記のコードの場合、別のビュー(詳細ビュー)に移動して戻ってくるとtextFieldも無効になります。ビューコントローラの代表団についての詳細は

- (void)viewDidLoad 
{ 
    [textfield setEnable:NO]; 
} 

:あなたはそれをしたくない場合は、次のコードを使用してもUIViewController Class Reference

1

あなたはストーリーボードを使用している場合、あなたは単純に「オフにすることができますTextFieldの「有効」チェックボックスをオンにします。トリックをする必要があります。

関連する問題