//刪除第一個元素
[self.data removeObjectAtIndex:0];
//刷新表視圖---重新執行數據源方法和代理方法
[self.tableView reloadData];
//把第2個單元格的內容改為“呵呵”
//構建IndexPath
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
//取到單元格
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"呵呵";
//輸出在屏幕上顯示的單元格的內容
NSArray *cells = [self.tableView visibleCells];
for (UITableViewCell *cell in cells) {
NSLog(@"%@", cell.textLabel.text);
}
//輸出在屏幕上顯示的單元格的下標
NSArray *indexPaths = [self.tableView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in indexPaths) {
NSLog(@"%ld", indexPath.row);
}
// 滑動到指定的位置,可以配置動畫
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:10 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:true];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
NSString *fontName = self.data[indexPath.row];
cell.textLabel.text = fontName;
// cell.textLabel.font = [UIFont fontWithName:fontName size:20];
return cell;
}
//設置section頭部、尾部視圖的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 80;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 80;
}
//自定義頭標題
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 200)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 30)];
label.text = @"123213";
label.backgroundColor = [UIColor whiteColor];
[view addSubview:label];
NSLog(@"%@:",view);
view.backgroundColor = [UIColor blueColor];
return view;
}
//設置單元格的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return 100;
}else if (indexPath.row == 1) {
return 200;
}
return 44;
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。