添加
<UITableViewDelegate, UITableViewDataSource>
You can use tableView in your UIViewController
@interface MyViewController:UIViewController<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic,retain) IBOutlet UITableView *mytableview;
Then in your viewController xib file create a tableview in view. connect it to the mytableview in files owner.Also DONT FORGET to set delegate and data source to files owner.
Later in your .m file create these functions and modify it according to your data.
@synthesize mytableView;
[mytableView setDelegate:self];
[mytableView setDataSource:self];
- (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);
}