2012-09-13 19 views
0

我需要一個像這樣的列表:如何獲得像Phone.app-「最近的選項卡」或Mail.app-「郵件列表」的TableViewCell


「我的標題」。 。 。 。 。 。 。 。 。 。 。 「10:20 AM」
「Created-by:meadlai」

「TitleString」。 。 。 。 。 。 。 。 。 。 。 「09:33 AM」
「Created-by:meadlai」

「TextLabel」。 。 。 。 。 。 。 。 。 。 。 「11:59 AM」
「detailTextLabel」

有三個字段:標題,創建者,時間。
它幾乎像 Phone.app「最近呼叫」的風格。
Mail.app的mailList。我不認爲它需要一個自定義的UITableViewCell。
我可以使用System-UITableViewCell創建一個像它一樣的列表嗎?
任何線索或代碼?非常感謝你。

+0

cell.textLabel.text = @「Victoria」; cell.detailTextLabel.text = @「created-by:mead」;如何在右側添加時間? – meadlai

+0

最後,我把它弄出來......,使用accessoryView
cell.textLabel.text = @「Victoria」; cell.detailTextLabel.text = @「created-by:mead」; UILabel * time = [[UILabel alloc] initWithFrame:CGRectMake(5,5,80,20)]; time.text = @「05:59 PM」; cell.accessoryView = time; – meadlai

回答

1
 cell.textLabel.text = @"Victoria"; 
     cell.detailTextLabel.text = @"created-by:mead"; 
     UILabel* time = [[UILabel alloc]initWithFrame:CGRectMake(5,5,80,20)]; 
     time.text = @"05:59 PM"; 
     cell.accessoryView = time; 

完成。

+0

我已經做到了......哈哈感謝所有回覆。 – meadlai

+0

唯一的問題是單元格不能有DetailDisclosureButton,這是Phone.app仍然有的東西。 – newenglander

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

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

    } 

    cell.textLabel.text = @"Some Name"; 
    cell.detailTextLabel.text = @"Some text underneath"; 

    return cell; 
} 

特別是這行代碼假設您有一個像TableViewCell phone.app

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

    UITableViewCellStyleSubtitle 
+0

但是,如何添加[時間],一個右側? – meadlai

1

參考UITableView

希望這將幫助你解決你所有的問題....

1

也許更改單元格的accessoryView,因爲沒有像你想要的樣式。不過,自定義單元類可能會使事情變得更簡單。

枚舉各種樣式的單元格。

typedef enum { 
    UITableViewCellStyleDefault, 
    UITableViewCellStyleValue1, 
    UITableViewCellStyleValue2, 
    UITableViewCellStyleSubtitle 
} UITableViewCellStyle; 

單元格使用的標準附件控件的類型。

typedef enum { 
    UITableViewCellAccessoryNone, 
    UITableViewCellAccessoryDisclosureIndicator, 
    UITableViewCellAccessoryDetailDisclosureButton, 
    UITableViewCellAccessoryCheckmark 
} UITableViewCellAccessoryType; 
0

爲別人尋找一個快速的解決方案,還允許使用DetailDisclosureButton的,你可以使用像TDBadgedCell一個庫,它允許你把徽章上一個單元格的左側。如果您不希望突出顯示徽章,請相應地設置badgeTextColorbadgeColor

相關問題