1.先附上代码
#import "CardGameViewController.h"
@interface CardGameViewController ()
@end
@implementation CardGameViewController
NSArray *arrayForTable;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_firstTable.dataSource=self;
_firstTable.delegate=self;
arrayForTable=@[@"第1行",
@"第2行",
@"第3行",
@"第4行",
@"第5行",
@"第6行",
@"第7行",
@"第8行",
@"第9行",
@"第10行"];
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrayForTable count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *tableIdentifier=@"firstTableCell";
UITableViewCell *thisCell =[tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if(thisCell==nil)
{
thisCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
}
thisCell.textLabel.text=[arrayForTable objectAtIndex:[indexPath row]];
return thisCell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
如果要将一个表格分割成两个sections,则需要加入下列代码
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
然后,在进行两个必须实现的方法的时候,分别提取indexPath的section的值进行比较分别赋值就行了,注意从0开始,而且section的分割符也可以改变。