在开始使用其 dequeueReusableCellWithIdentifier 委托之前,有人问我一个问题,即表格视图的单个视图中有多少个单元格。
I used the following program but it resets after 12 rows and begins with 1 again.
NSMutableArray *array;
-(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];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text=cellValue;
}
return cell;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
Run Code Online (Sandbox Code Playgroud)
And my viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
array = [[NSMutableArray alloc]init]; …Run Code Online (Sandbox Code Playgroud)