私はこれに何時間も本当に困惑していたので、助けを求める時が来たと思いました!
サブクラス ( )UITextField
に埋め込まれているのテキスト値にアクセスしようとしています。UITableViewCell
QuestionCell
問題は、メソッドでセルにアクセスしようとすると、cellForRowAtIndexPath
(NULL) が返されることです。
QuestionCell *qc = (QuestionCell*)[questionsTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSLog(@"qc %@",qc); // Gives "qc (NULL)" if there's text in the custom cell
UITextField
これは、カスタム セルにテキストが入力されている場合にのみ発生します。テキストがない場合、期待どおりにセルが返されます。
私はストーリーボードでXCode4.2を使用しており、カスタムスタイルとクラスを使用していますUITableViewCell
ここに私のQuestionCell.hがあります
#import <UIKit/UIKit.h>
@interface QuestionCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *correctionLabel;
@property (weak, nonatomic) IBOutlet UIImageView *correctionMark;
@property (weak, nonatomic) IBOutlet UILabel *pronounLabel;
@property (weak, nonatomic) IBOutlet UITextField *answerInput;
@end
そしてセルは通常のデリゲートメソッドで作成されます
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0)
{
QuestionCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"QuestionCell"];
NSString *pronoun = nil;
switch (indexPath.row) {
case 0:
pronoun = @"je";
break;
case 1:
pronoun = @"tu";
break;
case 2:
pronoun = @"il";
break;
case 3:
pronoun = @"nous";
break;
case 4:
pronoun = @"vous";
break;
case 5:
pronoun = @"ils";
break;
default:
break;
}
cell.pronounLabel.text = pronoun;
return cell;
}
if (indexPath.section == 1)
{
ActionCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"ActionCell"];
return cell;
}
return nil;
}