我想創建一個包含在另一個視圖中的自定義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