uitableview學習---1,uitableview---1

來源:互聯網
上載者:User

uitableview學習---1,uitableview---1

#import "ViewController.h"@interface ViewController ()@property (strong,nonatomic) NSArray *bj;@property (strong, nonatomic)NSArray *gd;@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];    self.bj = @[@"東城", @"西城", @"宣武", @"崇文"];    self.gd = @[@"廣東", @"佛山", @"深圳"];}#pragma mark  -TableView的資料來源方法#pragma mark 分組數- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 2;}#pragma mark 每個分組中顯示的表格個數,指定每個分組中的行數- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    if (section == 0) {        return self.bj.count;    }else{        return self.gd.count;    }}#pragma mark 每個表格中顯示的資料內容,這裡面的內容是由資料來源負責的。//@interface NSIndexPath (UITableView)////+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;////@property(nonatomic,readonly) NSInteger section;//@property(nonatomic,readonly) NSInteger row;////@end//可以通過當前的indexPath判斷出當前的行和組- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];        NSString *cityName = nil;    //組    if(indexPath.section == 0)      //0組    {        cityName = _bj[indexPath.row];    }else{        cityName = _gd[indexPath.row];    }    [cell.textLabel setText:cityName];    return cell;}#pragma mark  分組的標題- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{    return section == 0 ? @"北京" : @"廣東";}#pragma mark 分組底部的子標題,通常用於描述- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{    return section == 0 ? @"北京有烤鴨" : @"廣東有東莞";}@end






小弟剛接觸xcode的編程,想學一下表格(UITableView)方面的基本操作,給出詳細指導,非常感謝

這裡完全打不下那麼多字啊。給LZ一個簡要的學習過程吧。
TableView主要遵從兩個協議,一個叫TableViewDataSource,另一個叫TableViewDelegate。看名字就知道一個叫資料來源,一個叫委託,無論LZ用何種方式建立表視圖(IB或者純程式碼),都需要設定表視圖的委託和資料來源,而被設定為表視圖委託和資料來源的類就需要實現上文所說的兩個協議中的方法,否則是不能響應表視圖的委託請求和資料請求的。所以學習方法也就很明白了,開啟IDE,查看前文所述兩個協議的具體內容(都有英文注釋的哦),在你自己的類中實現他們即可。熟悉了表視圖之後就要關注一下它的父類。
UITableView繼承自UIScrollView(滾動視圖),既然已經熟悉了表視圖,熟悉一下它的父視圖是沒壞處的,畢竟一些表視圖的效果(比如滾動重新整理什麼的)是需要用到滾動視圖的方法和資料成員的。
最後,表視圖是IOS系統UI中重要的組成不分,是非常重要的一個控制項,預祝LZ學習順利
 
iOS7下,UINavigation中加入Grouped類型的UITableViewCell會有一段空白,怎調整?

cell是不分類型的,只有UITableView會分Plain和Group類型, 還有 UINavigationBar上邊一般也不加Cell,所以搞不清楚樓主想要做什麼。。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.