您可以在 UIViewController 中使用 tableView
@interface MyViewController:UIViewController<UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *mytableview;
}
@property(nonatomic,retain) IBOutlet UITableView *mytableview;
然后在您的 viewController xib 文件中在视图中创建一个 tableview。将其连接到文件所有者中的 mytableview。也不要忘记将委托和数据源设置为文件所有者。
稍后在您的 .m 文件中创建这些函数并根据您的数据对其进行修改。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //how many sections in your tableView
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [myArray count]; //how many rows you have
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = @"title";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog("%d.row selected",indexPath.row);
}