私はビューの上部にツールバーが必要なので、私はtableViewControllerを使用することはできませんので、UIViewController内にtableViewを配置したいと思います。私はtableViewクラスを作成し、それの中に必要な関数があると思ったものを入れましたが、何かが欠落しているか、どこかに間違ったものを置いているに違いありません。あなたはおそらくUITableView
をサブクラス化する必要はありません.HTableView内のUIViewController
import <UIKit/UIKit.h>
@interface TestTV : UITableView
@property(strong,nonatomic)NSArray *arr;
@end
.M
#import "TestTV.h"
@implementation TestTV
@synthesize arr = _arr;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
_arr = [[NSArray alloc]initWithObjects:@"HEJ",@"FOO", nil];
return _arr.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];
}
NSString *cellValue = [_arr objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
@end
それがうまくいった!ありがとうございました:) –
テーブルビューのセルやツールバーのボタンからセルを切り離すことはできません –
ストーリーボードのセグを話していると、私はそれに慣れていません。一方、必ず 'IBAction'と' tableView:didSelectRowAtIndexPath: 'デリゲートメソッドを使用して、必要なものを実現してください。 – warrenm