UITabelView


實現協議:UITabelDelegate 和UITabelViewDataSource

@interface ViewController :UIViewController<UITableViewDelegate,UITableViewDataSource>



//初始化一個數組.

- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    tabelData=[NSArrayarrayWithObjects:@"爲什麼放棄治療",@"還能不能一起玩耍了",@"TM的在逗我",nil];

    

}


在.m中實現UITableViewDataSource的兩個方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

   return [tabelDatacount];//返回的是表單的行數

}

//單元格內容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

   staticNSString *table=@"tableItem";

    UITableViewCell *cell =[tableViewdequeueReusableCellWithIdentifier:table];

    

   if (cell==nil) {

        cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:table];

    }

    cell.textLabel.text=[tabelDataobjectAtIndex:indexPath.row];//設置單元格的內容

    cell.imageView.image=[UIImageimageNamed:@"panda"];//包含圖片

   return cell;

    [cellrelease];

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章