のサブクラスがありUITableViewCell
ます。私のサブクラスにはいくつかUILabel
のが含まれています。サブクラスでこれらのラベルを、私のすべてのテーブルビューセルに適用されるデフォルト設定に初期化する必要があります。
私はこれに使うべきだと読んだinitWithCoder
。関数が呼び出されており、関数のinitWithCoder
各行をステップスルーでき、モーションを通過しているように見えます。ただし、アプリケーションを実行すると、適用されているプロパティが表示されません。最も注目すべきは、フォントが変更されていないことです。UILabel
自分で変更しているプロパティが実際に保存または表示されているとは思いません。
このサブクラスを。と組み合わせて使用していStoryboard
ます。変更がに反映されないことはわかっていますがStoryboard
、コードが実行されているにもかかわらず、アプリケーションの実行時にも変更が反映されていません。
編集:オーバーライドを試みる前にinitWithCoder
、このロジックを実行するこれらのサブクラスにインスタンスメソッドがありました。そのインスタンスメソッドを。内で呼び出すだけですcellForRowAtIndexPath
。このメソッドは機能していましたが、このサブクラスのこのロジックを自動的に実行するのが便利だと思いました。
何か案は?私のコードは以下の通りです:
#import "ThreadListCell.h"
@implementation ThreadListCell
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
// adjust the font settings of the title
self.title.font = [UIFont fontWithName:@"SourceSansPro-Black" size:16];
self.title.textColor = [UIColor colorWithWhite:0.267f alpha:1.0f];
// adjust the font settings of the subtitle
self.text.font = [UIFont fontWithName:@"SourceSansPro-Light" size:14];
self.text.textColor = [UIColor colorWithWhite:0.267f alpha:0.9f];
self.text.textColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
// adjust the font settings of the location
self.location.font = [UIFont fontWithName:@"SourceSansPro-Light" size:8];
self.location.textColor = [UIColor colorWithWhite:0.267f alpha:0.9f];
// adjust the UILabel settings of the title
self.title.numberOfLines = 0;
self.title.lineBreakMode = UILineBreakModeTailTruncation;
// adjust the UILabel settings of the subtitle
self.text.numberOfLines = 0;
self.text.lineBreakMode = UILineBreakModeTailTruncation;
// adjust the UILabel settings of the location
self.location.numberOfLines = 0;
self.location.lineBreakMode = UILineBreakModeTailTruncation;
self.location.textAlignment = UITextAlignmentRight;
}
return self;
}
@end
そしてヘッダー:
#import <UIKit/UIKit.h>
@interface ThreadListCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *text;
@property (nonatomic, weak) IBOutlet UILabel *title;
@property (nonatomic, weak) IBOutlet UILabel *location;
@end