<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### UITableView 與其他相關組件一樣,視圖控制器須實現:數據源(UITableViewDataSource) ,委托(UITableViewDelegate)兩個協議,(然后實現其方法) 。這樣當視圖控制器成為UITableView的數據源與委托時,就能為其工作(調用被實現的方法)。 ### 一:創建UITableview,默認是無格式表。 ![](https://box.kancloud.cn/2016-06-12_575cce7bd9ed4.png) ### 1)接下來就是創建輸出口(使視圖控制器得到界面上組建的實例,這里就是UITableView),連接委托(delegate),數據源(datasource),關于他們的具體解釋上一篇日志已經提到,這里不做過多介紹。 ![](https://box.kancloud.cn/2016-06-12_575cce7c1db62.png) ### 2)創建一個plist文件用于定義數據(為視圖顯示提供數據):點擊new file----->resource----->property list ![](https://box.kancloud.cn/2016-06-12_575cce7c41632.png) ### 3)在plist文件中定義數據: ![](https://box.kancloud.cn/2016-06-12_575cce7c61293.png) ### 4)添加數據規則: ![](https://box.kancloud.cn/2016-06-12_575cce7c810af.png) ### 5)查看數據代碼: ![](https://box.kancloud.cn/2016-06-12_575cce7cb0336.png) ### 6)由此可見xcode的功能還是很好的,只要我們在界面上直觀的點擊加號,減號,添加數據和數據類型,在后臺就會自動生成代碼格式,很方便。??? ok前期的數據工作就準備好了! ### 二:控制器.h文件遵循UITableViewDataSource,UITableViewDelegate兩個協議,然后.m文件實現其方法(為視圖顯示做工作)。 ### 樣例代碼: ### 1)MyTableViewGroupController.h文件中: ![](https://box.kancloud.cn/2016-06-12_575cce7ce9f19.png) ### 2) ### 1. MyTableViewGroupController.m文件中:在viewDidLoad方法中初始化數據(從plist文件中獲得數據) ![](https://box.kancloud.cn/2016-06-12_575cce7d161a6.png) ### 2. 實現 協議UITableViewDataSource的五個方法使數據按照操作顯示在屏幕上,這里并沒有實現協議UITableViewDelegate的方法。 ~~~ #pragma mark- #pragma mark Table View Group -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ //返回(向系統發送)分區個數,在這里有多少鍵就會有多少分區。 return [self.MyKey count]; } //所在分區所占的行數。 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ //獲取當前分區所對應的鍵(key)。在這里鍵就是分區的標示。 NSString *key=[self.MyKey objectAtIndex:section]; //獲取鍵所對應的值(數組)。 NSArray *nameSec=[self.resource objectForKey:key]; //返回所在分區所占多少行。 return [nameSec count]; } //向屏幕顯示。 -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //獲得所在分區的行數 NSInteger row=[indexPath row]; //獲得分區值 NSInteger section=[indexPath section]; //利用分區獲得鍵值 NSString *key=[self.MyKey objectAtIndex:section]; //利用鍵值獲得其所對應的值 NSArray *MySectionArr=[self.resource objectForKey:key]; //定義標記,用于標記單元格 static NSString *SectionTableMyTag=@"dong"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:SectionTableMyTag]; //如果當前cell沒被實例(程序一開始就會運行下面的循環,直到屏幕上所顯示的單元格格全被實例化了為止,沒有顯示在屏幕上的單元格將會根據定義好的標記去尋找可以重用的空間來存放自己的值) if (cell==nil) { cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionTableMyTag]; } cell.textLabel.text=[MySectionArr objectAtIndex:row]; return cell; } //把每個分區打上標記key -(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ NSString *key=[self.MyKey objectAtIndex:section]; return key; } //在單元格最右放添加索引 -(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView{ return self.MyKey; } ~~~ ### 3)看運行結果: ![](https://box.kancloud.cn/2016-06-12_575cce7d34e36.png) ### 很明顯這是一個分區索引表。如果只想要無格式表,就是不用寫numberOfSectionsInTableView返回分區數,這個方法。同理如果想要除去索引,只需不寫其方法sectionIndexTitlesForTableView即可。 ### 4)直接改為分組表 ![](https://box.kancloud.cn/2016-06-12_575cce7d4dfec.png) ![](https://box.kancloud.cn/2016-06-12_575cce7d81bd5.png) ### 可見既有分組又有索引,但蘋果不建議這樣寫,可能是出于對程序優化的考慮。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看