表視圖

1.   UITabBarController   UINavigationController  UIViewController
UITableView


缺少一份了堅持!
欲帶王冠,必先承其重!
你放縱的每一秒,又有多少人在拼命!
你所聽到的忠告,是別人走了多少個彎路,總結出來的!


2.協議<UITableViewDelegate,UITableViewDataSource>




以爲是你  家的味道  兄弟乾杯


3.    _sectionList=@[@[@"搜索"],@[@"設置",@"狀態"]];
    [tabView release];
}
//有幾個section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _sectionList.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *array= _sectionList[section];
    return array.count;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.textLabel.text=_sectionList[indexPath.section][indexPath.row];
    return cell;
    [cell release];
}




4.獲取當前工程下目錄的路徑
NSString *path=[[NSBundle mainBundle]pathForResource:@"font" ofType:@"plist"];


5.-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
自定義section頭部視圖
.tableHeaderView 定義整個視圖的頭部視圖


6._fonts=[[UIFont familyNames]retain]  記住一定要retain 不然的話會出野指針


7.static NSString *identifier=@"myCell";
//查詢池子中是否有空閒的單元格
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==Nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.font=[UIFont fontWithName:_fonts[indexPath.row] size:14];
    cell.textLabel.text=_fonts[indexPath.row];
單元格的重用法




8.plist文件  格式第一個爲root默認 字典


9.背景透明
[UIColor clearColor]


10.高度自適應 核心代碼
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *text=[_data objectAtIndex:indexPath.row];
    CGSize size=[text sizeWithFont:[UIFont systemFontOfSize:14]constrainedToSize:CGSizeMake(300, 1000)];
  
    return  size.height+20;
}


11.NSString *text=[_data objectAtIndex:indexPath.row];  這是取得別人的值 不是重新定義的數


12.單元格複用問題
    if (self.indexPath != nil) {
        if (self.indexPath.section == indexPath.section && self.indexPath.row == indexPath.row) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        } else {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
當前選用的是否等於將要顯示的,是的話一樣
不是的話不一樣


//當前選中的事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    //設置輔助視圖的樣式
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    
    //記錄當前選中單元格的索引
    self.indexPath = indexPath;
}


//上一次選中的事件    處理上一次 輔助圖標不消失問題
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    //設置輔助視圖的樣式
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}


13.UISearchBar  搜索框


14.搜索過濾
    //初始化謂詞的時候不能加佔位符  這是bug
    NSString *p=[NSString stringWithFormat:@"SELF LIKE[c]'%@*'",text];
    NSPredicate *predicate=[NSPredicate predicateWithFormat:p];
    self.filterData=[_fonts filteredArrayUsingPredicate:predicate];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章