UITableView

目錄
    1.1 不顯示無(wú)用cell
    1.2 分割線位置調(diào)整
    1.3 刷新局部
    1.4 滾動(dòng)到底部
    1.5 詳情按鈕點(diǎn)擊
    1.6 頭圖放大功能
    1.7 側(cè)滑刪除
    1.8 索引
1.1 不顯示無(wú)用cell

self.tableView.tableFooterView = [[UIView alloc]init];

1.2 分割線位置調(diào)整

[self.mainTableView setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
1.3 刷新局部

NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[self.mainTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
1.4 滾動(dòng)到底部

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:3];
[self.mainTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
1.5 詳情按鈕點(diǎn)擊

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"%ld",(long)indexPath.row);

}
1.6 頭圖放大功能

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width //屏幕寬度

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height //屏幕高度

#define IMAGE_HEIGHT 200 //屏幕高度


@interface ViewController ()< UITableViewDataSource,UITableViewDelegate >

@property (weak, nonatomic) IBOutlet UITableView *mainTableView;

@property (nonatomic , strong)UIImageView *headerImageView;

@property (nonatomic , strong)UIView *headerView;

@end

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 
    SCREEN_WIDTH, IMAGE_HEIGHT)];
    
    UIImage *image = [UIImage imageNamed:@"1"];
    
    self.headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake
   (0, 0, SCREEN_WIDTH, IMAGE_HEIGHT)];
    
    self.headerImageView.image = image;
    
    [self.headerView addSubview: self.headerImageView];
    
    self.mainTableView.tableHeaderView = self.headerView;
    
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat yOffset = self.mainTableView.contentOffset.y;
    
    //向上偏移量變正 向下偏移量變負(fù)
    
    if (yOffset <= 0) {
        
        CGFloat factor = ABS(yOffset)+ IMAGE_HEIGHT;
        
        CGRect f = CGRectMake(-([[UIScreen mainScreen] bounds].size.width
        *factor/(IMAGE_HEIGHT)-[[UIScreen mainScreen] bounds].size.width)/2,
        -ABS(yOffset), [[UIScreen mainScreen] bounds].size.width*factor/
        (IMAGE_HEIGHT), factor);
        
        self.headerImageView.frame = f;
        
    }else {
        
        CGRect f = _headerView.frame;
        
        f.origin.y = 0;
        
        _headerView.frame = f;
        
        self.headerImageView.frame = CGRectMake(0, f.origin.y, 
        [[UIScreen mainScreen] bounds].size. width, 200);
        
    }
}

1.7.1 側(cè)滑刪除

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
    //return UITableViewCellEditingStyleInsert;
    
}


- (void)tableView:(UITableView *)tableView 
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
 forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(editingStyle == UITableViewCellEditingStyleDelete)
        
        
    {
        
        [self readButtonClicked:indexPath];
        
    }
    
}

// 設(shè)置返回的字段名字
- (NSString *)tableView:(UITableView *)tableView 
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
 {    
    return @"標(biāo)為已讀";
    
}


1.7.2 自定義側(cè)滑刪除

- (NSArray *)tableView:(UITableView *)tableView 
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewRowAction *deleteAction=[UITableViewRowAction 
rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪
除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        
        NSLog(@"刪除!");    
    }];
    
    deleteAction.backgroundColor=[UIColor redColor];
    
    UITableViewRowAction *otherAction=[UITableViewRowAction 
rowActionWithStyle:UITableViewRowActionStyleDefault title:@"其他"
handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        
        NSLog(@"其他");
        
    }];
    
    otherAction.backgroundColor=[UIColor blueColor];
    
    return @[deleteAction,otherAction];
    
}

1.8 索引

//索引
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    
    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
    
    for (int i=0; i < self.firstNumArray.count; i++) {
        
        [arr addObject:self.firstNumArray[i][0]];
        
    }
    
}

//索引Index
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
    
    return index;
    
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末框咙,一起剝皮案震驚了整個(gè)濱河市煤墙,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌馍刮,老刑警劉巖信夫,帶你破解...
    沈念sama閱讀 222,183評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異卡啰,居然都是意外死亡静稻,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門匈辱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)振湾,“玉大人,你說(shuō)我怎么就攤上這事亡脸⊙禾拢” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 168,766評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵浅碾,是天一觀的道長(zhǎng)大州。 經(jīng)常有香客問(wèn)我,道長(zhǎng)垂谢,這世上最難降的妖魔是什么厦画? 我笑而不...
    開(kāi)封第一講書人閱讀 59,854評(píng)論 1 299
  • 正文 為了忘掉前任,我火速辦了婚禮滥朱,結(jié)果婚禮上根暑,老公的妹妹穿的比我還像新娘力试。我一直安慰自己,他們只是感情好购裙,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,871評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布懂版。 她就那樣靜靜地躺著,像睡著了一般躏率。 火紅的嫁衣襯著肌膚如雪躯畴。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 52,457評(píng)論 1 311
  • 那天薇芝,我揣著相機(jī)與錄音蓬抄,去河邊找鬼。 笑死夯到,一個(gè)胖子當(dāng)著我的面吹牛嚷缭,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播耍贾,決...
    沈念sama閱讀 40,999評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼阅爽,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了荐开?” 一聲冷哼從身側(cè)響起付翁,我...
    開(kāi)封第一講書人閱讀 39,914評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎晃听,沒(méi)想到半個(gè)月后百侧,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,465評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡能扒,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,543評(píng)論 3 342
  • 正文 我和宋清朗相戀三年佣渴,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片初斑。...
    茶點(diǎn)故事閱讀 40,675評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡辛润,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出越平,到底是詐尸還是另有隱情频蛔,我是刑警寧澤,帶...
    沈念sama閱讀 36,354評(píng)論 5 351
  • 正文 年R本政府宣布秦叛,位于F島的核電站晦溪,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏挣跋。R本人自食惡果不足惜三圆,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,029評(píng)論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧舟肉,春花似錦修噪、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 32,514評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至整慎,卻和暖如春脏款,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背裤园。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,616評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工撤师, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人拧揽。 一個(gè)月前我還...
    沈念sama閱讀 49,091評(píng)論 3 378
  • 正文 我出身青樓剃盾,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親淤袜。 傳聞我的和親對(duì)象是個(gè)殘疾皇子痒谴,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,685評(píng)論 2 360

推薦閱讀更多精彩內(nèi)容