2011-05-10 5 views
1

どのように私はテキストボックスとボタンでUITableViewCellを作成できますか?このコードで試しましたが、テキストボックスは表示されませんが、ボタンは表示されません。テキストボックスとボタンでUITableViewCellを作成しますか?

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierWithTextBox]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierWithTextBox] autorelease]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     CGRect textRect = CGRectMake(10, 20, 500, 31); 
     UITextField *myfield = [[UITextField alloc]initWithFrame:textRect]; 
     myfield.borderStyle = UITextBorderStyleRoundedRect; 
     myfield.font = [UIFont systemFontOfSize:22.0]; 
     myfield.adjustsFontSizeToFitWidth = YES; 
     myfield.minimumFontSize = 2.0; 

     myfield.clearButtonMode = UITextFieldViewModeWhileEditing; 
     myfield.keyboardType = UIKeyboardTypeDefault; 
     myfield.autocorrectionType= UITextAutocorrectionTypeNo; 
     myfield.autocapitalizationType=UITextAutocapitalizationTypeNone; 
     myfield.returnKeyType=UIReturnKeyDone; 


     UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     doneButton.frame = CGRectMake(520, 10, 30, 30); // position in the parent view and set the size of the button 
     [doneButton setTitle:@"Registry now" forState:UIControlStateNormal]; 
     // add targets and actions 
     [doneButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
     // add to a view    

     [cell.contentView addSubview: myfield]; 
     [cell.contentView addSubview: doneButton]; 
     [doneButton release]; 
     [myfield release]; 
    } 

答えて

0

doneButton.frame = CGRectMake(520、10、 30、30)。

このコードで問題が発生しました。 IPhoneはポートレートモードで320幅、風景モードで480幅を持っています。 x = 520を設定すると、それを見ることはできません。

+0

忘れてしまった!私はipadをコーディングしています。それについて申し訳ありません! – 9891541

1

は、この行を削除します。

[doneButton release]; 

あなたは、自動解放オブジェクトを返すbuttonWithTypeを使用してボタンを作成しています。

+0

愚かな気分!ありがとうございます! – 9891541

0

以下を実行します。

doneButton.frame = CGRectMake(520、10、30、30);

上記の行に問題があります。 iPhoneアプリでこれを使用している場合、その幅は320pxに過ぎません。 iPadでこれを使用している場合は問題ありません。

上記の操作をもう1つ実行してください。ボタンに背景色を追加してください。

[doneButton setBackgroundColor:[UIColor blackColor]];

関連する問題