溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

OC中UITableView的屬性用法

發布時間:2020-08-02 09:57:47 來源:網絡 閱讀:507 作者:ladispartion1 欄目:開發技術


    //刪除第一個元素

    [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;

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女