2015-07-20 79 views
0

是否可以將圖片添加到我的搜索欄結果中?我可以使用以下內容添加文本:搜索欄結果在文本旁邊添加圖片

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
let cell = tableView.dequeueReusableCellWithIdentifier(self.identifier) as! UITableViewCell 

var text: String? 
    if tableView == self.searchResultsController?.tableView { 
     if let results = self.results { 
      text = self.results!.objectAtIndex(indexPath.row) as? String 
     } 
    } else { 
     // text = MyVariables.users[indexPath.row] as? String 
    } 

    cell.textLabel!.text = text 

    return cell 
} 
+0

你必須添加圖像視圖到你的單元格。 –

+0

@ T_77設置圖像視圖後,圖像如何知道進入文本的左側? – SlopTonio

+0

你是否以編程方式設置圖像視圖? –

回答

0

您只需將一個UIImage添加到您的手機。

cell.imageView?.image = UIImage(named: "YourImageNameGoesHere") 

UITableViewCellimageView屬性被放置在左邊。

[...]如果設置了圖像,它會出現在單元格左邊的 的任意標籤之前。 [...]

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/occ/instp/UITableViewCell/imageView

希望這有助於。

+0

是的,圖像應該出現在左邊。你想把它放在哪裏? –

+0

很抱歉,您問過如何在搜索結果中顯示圖片。你現在在問一個不同的問題嗎? –