第一步,创建一个tableView。并且在connection-inspector里面,设置好dataSource 和delegate:点击右侧的小圆圈然后连线到fileowner的地方。
第二步:在ViewController.h中添加代理:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
<UITabBarDelegate,UITableViewDataSource>
{
NSArray *tableIndexData;
}
@property (nonatomic, retain) NSArray *tableIndexData;
@end
第三步:在ViewController.m中添加一下代码:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize tableIndexData;
- (void)viewDidLoad {
self.tableIndexData = [[NSArray alloc] initWithObjects:@"收件箱",@"草稿",@"已发送",@"废纸篓",@"收件箱",@"草稿",@"已发送",@"废纸篓", @"收件箱",@"草稿",@"已发送",@"废纸篓", @"收件箱",@"草稿",@"已发送",@"废纸篓", @"收件箱",@"草稿",@"已发送",@"废纸篓", nil];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.tableIndexData count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *tableIdentifier = @"tableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
}
cell.textLabel.text = [self.tableIndexData objectAtIndex:[indexPath row]];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
输出的结果如下: