【发布时间】:2010-08-24 11:27:44
【问题描述】:
这可能吗?我只想在我当前的视图中有一张小桌子......这就是我想要做的:
.h 文件
#import <UIKit/UIKit.h>
@interface IngredientsRootView : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *ingredientsTable;
}
@property (nonatomic, retain) UITableView *ingredientsTable;
@end
.m 文件我有委托和数据源方法以及这段代码:
ingredientsTable = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, 300) style:UITableViewStylePlain];
[ingredientsTable setDelegate:self];
[ingredientsTable setDataSource:self];
[self.view addSubview:ingredientsTable];
应用不会崩溃,但不会显示表格。目前我只是按照以下方式设置所有内容:
#pragma mark -
#pragma mark Table view data source
- (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 10;
}
// the appearance of table view cells.
- (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];
}
// Configure the cell...
cell.textLabel.text = @"Hello";
return cell;
}
我做错了什么?谢谢
【问题讨论】:
-
我想这取决于你在哪里初始化 tableView,你是在控制器的
initWithNib:方法中做的吗? -
哦抱歉....没有 viewDidLoad :)
-
尝试在 Interface Builder 中将其链接为 IBOutlet 并将初始化留给他,只保留委托/数据源部分
标签: iphone uitableview subview addsubview