隨筆-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和大家討論,大家一定能收獲很多  回復  更多評論
            
          主站蜘蛛池模板: 祁东县| 卢湾区| 修武县| 明溪县| 乌审旗| 兴海县| 醴陵市| 凤城市| 通河县| 墨脱县| 大埔县| 巴马| 静海县| 石城县| 云和县| 九龙坡区| 斗六市| 佳木斯市| 普洱| 泸溪县| 北流市| 略阳县| 平罗县| 高雄市| 怀柔区| 明星| 东兰县| 宜阳县| 昌黎县| 金川县| 宝清县| 阿克陶县| 固原市| 鸡东县| 丁青县| 澎湖县| 抚远县| 游戏| 安吉县| 田阳县| 班玛县|