我正在使用多個部分的表格視圖。在一個表格中查看具有文本標籤和詳細文本標籤以顯示數組對象的單元格。現在我想添加一個新的部分,在這一部分中,我將有更多的文字像段落。如何在文本視圖中顯示數據?如何在包含多個部分的表格視圖單元格中嵌入文本視圖?
{
var dataSection01:NSMutableArray = NSMutableArray()
var dataSection02:NSMutableArray = NSMutableArray()
var sectionTitleArray : NSMutableArray = NSMutableArray()
var arrayForBool : NSMutableArray = NSMutableArray()
var sectionContentDict : NSMutableDictionary = NSMutableDictionary()
in viewDidLoad()
sectionTitleArray = ["Assignment Information","Details"]
let tmp1 : NSArray = assignInfoArray
var string1 = sectionTitleArray .objectAtIndex(0) as? String
[sectionContentDict .setValue(tmp1, forKey:string1!)]
let tmp2 : NSArray = detailsInfoArray
string1 = sectionTitleArray .objectAtIndex(1) as? String
[sectionContentDict .setValue(tmp2, forKey:string1!)]
dataSection01 = [ "Name:", "Phone", "Email" so on]
dataSection02 = [ "Address", "Street", "State","ZipCode"]
//mapping like this using object mapper
assignInfoArray.addObject((newDetails?.clientName)!)
assignInfoArray.addObject((newDetails?.clientPhone)!)
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return sectionTitleArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let CellIdentifier = "CellRightDetail"
var cell :UITableViewCell?
cell = self.tableView.dequeueReusableCellWithIdentifier(CellIdentifier)
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: "CellRightDetail")
}
let manyCells : Bool = arrayForBool .objectAtIndex(indexPath.section).boolValue
if (!manyCells) {
// cell.textLabel.text = @"click to enlarge";
}
else{
let items: NSMutableArray = self.dataFromIndexPath(indexPath)
let content = sectionContentDict .valueForKey(sectionTitleArray.objectAtIndex(indexPath.section) as! String) as! NSArray
cell!.detailTextLabel?.text = content .objectAtIndex(indexPath.row) as? String
cell!.detailTextLabel?.textColor = UIColor.whiteColor()
cell!.textLabel?.textColor = UIColor.whiteColor()
cell!.textLabel?.font = UIFont(name:"Helvetica-Bold", size: 13.0)
cell!.textLabel?.text = items[indexPath.row] as? String
}
return cell!
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
if(arrayForBool .objectAtIndex(section).boolValue == true)
{
let tps = sectionTitleArray.objectAtIndex(section) as! String
let count1 = (sectionContentDict.valueForKey(tps)) as! NSArray
return count1.count
}
return 0;
}
func dataFromIndexPath(indexPath: NSIndexPath!) -> NSMutableArray!
{
if (indexPath.section == 0)
{
return dataSection01
}
else if (indexPath.section == 1)
{
return dataSection02
}
return nil
}
}
你能提供一個想象,顯示你想要達到的目標嗎? – Erik
@Ajay_Ajju,你應該編輯你的問題,向我們展示更多信息,你的問題不清楚,顯示你的代碼。 – aircraft
我認爲創建CustomTableViewCell是很好的答案 –