我想创建一个包含在另一个视图中的自定义UITableView。我已经能够将视图设置成几乎和我想要的一样。我只是想知道,我最需要的两种方法(tableView:cellForRowAtIndexPath
和tableView:didSelectRowAtIndexPath
)怎么没有被调用。请注意,我没有使用UITableViewController,但我正在使用UIViewController来控制tableView。创建一个自定义的UITableView
这里是我的代码
- (void)loadView {
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIView * contentView = [[UIView alloc] initWithFrame:applicationFrame];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
UIImageView * backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainBackground.jpeg"]];
[self.view addSubview:backgroundImageView];
CGRect tableFrame = CGRectMake(40, 40, 240, 310);
self.listView = [[UITableView alloc] initWithFrame:tableFrame];
self.listView.dataSource = self;
self.listView.delegate = self;
self.listView.scrollEnabled = NO;
self.listView.rowHeight = 50;
self.listView.backgroundColor = [UIColor clearColor];
self.listView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBgMid"]];
[self.view addSubview:self.listView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellRow %@", indexPath.row);
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Did Select Row%@", indexPath.row);
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}
对头文件,我已经实现了协议。我并不想为这个实际使用一个xib文件。我希望能够创建一个自定义表格视图。 – denniss 2012-07-30 03:18:55
你有什么东西真的出现在细胞中吗? – Pareshkumar 2012-07-30 04:13:55