UIViewController 内に UITableView を作成しようとしています。カスタム UITableViewCell もいくつか作成したいと思います。ただし、UILabel プロパティを UITableViewCell に追加する方法を理解するのに苦労しています。コードを実行すると、次のエラーが表示されます...「タイプ 'UITableViewCell' のオブジェクトにプロパティ '_label1' が見つかりません」
.h
@interface gideViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
}
@property (nonatomic, strong) IBOutlet UILabel *label1;
@property (nonatomic, strong) NSArray *data;
彼ら
@synthesize label1 = _label1;
@synthesize data = _data;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self._data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TableCell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];
}
//*********** This is where I get the compiler error ... "Property '_label1' not found on object of type 'UITableViewCell'"///
cell._label1.text = [self._data
objectAtIndex: [indexPath row]];
return cell;
}
- (void)viewDidLoad{
[super viewDidLoad];
self.data = [[NSArray alloc]
initWithObjects:@"ABC",
@"DEF",
@"XYZ",
@"JKY", nil];
}