隨筆-193  評論-715  文章-1  trackbacks-0
          原文地址: http://blog.sina.com.cn/s/blog_7e3132ca0100wyls.html
          在XCode對應頭文件中修改該類所繼承的父類:
          @interface TableViewController:UIViewController <UITableViewDataSource, UITableViewDelegate>
          {
          }
          在對應的.m文件中添加如下代碼:
          @implementation TableViewController
          {
          UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,320,460) style:UITableViewStylePlain];
          tableView.dataSource = self;
          tableView.delegate = self;
          [self.view addSubview:tableView];
          }
          這樣就在view上添加了一個tableView,但其樣式是默認的,其中的內容也是空白的,而且此時是無法運行的,因為在頭文件中添加了UITableViewDataSource和UITableViewDelegate兩個類,所以必須設置一些自定義tableView樣式的方法,下面列舉了一些相關的方法:
          設置Cell高度:
          -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
          設置SectionHeader高度:
          -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
          設置SectionFooter高度:
          -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
          設置Section數目:
          -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
           
          設置SectionHeader內容:
          -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
          設置各個Section中的Cell個數: 
          -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
          設置Cell內容: 
          -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
           
          設置Cell行縮進量:
          -(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
          設置Cell被選中響應前動作(例如:可用以判斷選中的Cell,來阻止其響應)
          -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
          設置Cell選中觸發響應:
          -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
          posted on 2011-12-29 09:12 Robin's Programming World 閱讀(2343) 評論(1)  編輯  收藏 所屬分類: 其它

          評論:
          # re: [轉]自定義UITableView 2012-11-01 22:58 | superchen
          博主把最核心,最常用的函數都羅列出來了!博主可以進IOS中高級開發群:118623167和大家討論,大家一定能收獲很多  回復  更多評論
            
          主站蜘蛛池模板: 合水县| 莱西市| 郯城县| 集安市| 万宁市| 呼图壁县| 正定县| 顺义区| 平江县| 南昌县| 安阳县| 鹤庆县| 三都| 湾仔区| 鹿泉市| 焦作市| 丽水市| 龙海市| 奉化市| 连山| 酒泉市| 余江县| 高青县| 平和县| 容城县| 兰考县| 鹤岗市| 昌吉市| 雅安市| 日照市| 保德县| 和政县| 宁波市| 达孜县| 手游| 崇明县| 恩平市| 安西县| 明星| 长兴县| 寿宁县|