2013-06-27 46 views
0

是否有一種簡單的方法可以讓我們在這裏看到像這樣的編號和邊框的tableview單元格。這是用不同的部分創建的嗎?iOS:自定義TableView單元格來模擬音樂播放器

enter image description here

+0

取決於您對「easy」的定義。沒有什麼魔法「讓它看起來像這樣」屬性,但是如果你對標題和自定義表格單元格感到舒服,那並不難。 – Kevin

回答

1

您需要創建一個自定義的UITableViewCell。

如果你使用故事板看這裏: 請參閱此鏈接http://mobile.tutsplus.com/tutorials/iphone/customizing-uitableview-cell/

如果不是這裏有一個破敗: 基本上創建自定義UITableViewCell和XIB繼承一個新的類。將UITableViewCell拖到XIB並將其設置爲您之前創建的類。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CustomCellIdentifier = @"CustomCellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; 

    if (cell == nil) { 
     //*- Load your custom XIB. objectAtIndex:0 says load the first item in the XIB. Should be your UITableViewCell that you dragged onto your XIB in Interface Builder. 
     cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0]; 
    } 

    //*- Customize the cell, i.e., cell.myLabel.text = @"Text"; 

    return cell; 
} 

使用這種技術,你可以用三個標籤,一個是數量,一個是歌曲的名字,一個用於首歌的時間佈置你的。爲邊框和顏色添加背景圖像視圖。

獲取表格中歌曲編號的一種簡單方法是使用indexpath。

cell.myLabel.text = [NSString stringWithFormat:@"%i", indexPath.row + 1]; 
+0

我走了創建自定義單元類的路線。沒有像我擔心的那樣浪費時間。 –