2016-02-19 109 views
-1

在這裏,我會告訴你的代碼片段,我使用:爲什麼detailTextLabel不可見

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *[email protected]"system"; 
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableIdentifier]; 

    if (cell==nil) { 
     cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier]; 
    } 

    cell.textLabel.text=[peoples objectAtIndex:indexPath.row]; 
    cell.textLabel.textColor=[UIColor whiteColor]; 
    cell.detailTextLabel.text=[location objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.textColor=[UIColor whiteColor]; 
} 
+0

你設定的細胞類型UITableViewCellStyleSubtitle? –

回答

2

的detailTextLabel不顯示與UITableViewCellStyleDefault風格細胞。改用UITableViewCellStyleSubtitle來初始化UITableViewCell,你應該看到你的detailTextLabel。

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

以下任何風格,可以按規定使用:

UITableViewCellStyleValue1,  // Left aligned label on left and right aligned label on right with blue text 

UITableViewCellStyleValue2,  // Right aligned label on left with blue text and left aligned label on right 

UITableViewCellStyleSubtitle // Left aligned label on top and left aligned label on bottom with gray text 
+1

基本上'UITableViewCellStyle'枚舉中的任何選項,_except_UITableViewCellStyleDefault都會顯示詳細的文本標籤。 –