UITableView (コントローラーではない) を含むアプリケーションを開発し、プログラムで追加しました。nibファイルは使用しませんでした。シミュレーターでは正常に動作することがわかりましたが、デバイステーブルでビルドすると表示されましたが、テキストが表示されませんでした。データソースとデリゲートは既に接続されています。
ここにいくつかのコード
if (kPortrait) {
optionTV = [[UITableView alloc] initWithFrame:CGRectMake(568, 75, 200, 44 * [optionArray count]) style:UITableViewStylePlain];
} else {
optionTV = [[UITableView alloc] initWithFrame:CGRectMake(824, 75, 200, 44 * [optionArray count]) style:UITableViewStylePlain];
}
[optionTV setAutoresizesSubviews:YES];
[optionTV setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[optionTV setDataSource:self];
[optionTV setDelegate:self];
optionTV.alpha = 0.0f;
optionTV.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.50];
[self.view addSubview:optionTV];
[UIView animateWithDuration:0.5f animations:^{
trafficBT.transform = CGAffineTransformMakeTranslation(-200, 0);
optionTV.alpha = 0.8;
}];
デリゲート メソッドの場合:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"tableView Data num row: %d", [optionArray count]);
return [optionArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.backgroundColor = [UIColor clearColor];
if (kIsIPhone) {
cell.textLabel.font = [UIFont systemFontOfSize:18];
} else {
cell.textLabel.font = [UIFont systemFontOfSize:20];
}
cell.textLabel.text = [optionArray objectAtIndex:indexPath.row];
return cell;
}