tableviewcontroal 是uiviewcontral 的子类;
//创建几行分区 默认是一
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSIndexPath *index;
index=[NSIndexPath indexPathForRow:b inSection:a];//第a个区域里的第b行。
[table scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionBottom animated:YES];
跳转到第index着行,第二个参数是个枚举的,第三个是动效。
有一个小问题, 就是在跳转到最后一个区域de时候总是显示越界了。
所以我们在判断到最后一个区域的时候要用倒数第二个区域的最后一行。。
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
// 分区中有几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return x;//是需要创建cell 的个数。
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
这个方法时候经常回出现bage 把forindexpath拿掉就可以实现了
重用机制
//查看使用过的cell中是否you空闲着没用的的cell,重用。
static NSString *CellIdentifier =@"Cell";
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];//判断是否有闲置的cell
if(!cell){
cell =[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];
//创建cell
}
NSString *string=[NSStringstringWithFormat:@"%@+%d",cell.textLabel.text,indexPath.row+1];
cell.textLabel.text=string;
NSLog(@"%d",indexPath.row);
UItableviewcell : image label accessory(指示条)