2016-05-16 10 views
0

私はXcode 7とSwiftを使用して小さなタスクリストアプリケーションを作成しています。ただし、日付ラベルなどのデータの一部は、左を除いてUITableViewCellの右側に配置します。 UITableViewCellの右側に日付ラベルを挿入するのにどのようなコードを使用しますか?UITableViewCellの右側にデータを配置する方法

私のViewController.swiftのコードは、TableViewがあります。

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 

// All Outlets Connected to StoryBoard 
@IBOutlet var BTN: UIButton! 
@IBOutlet var BTN2: UIButton! 
@IBOutlet var BTN3: UIButton! 
@IBOutlet var BTN4: UIButton! 
@IBOutlet var tbl: UITableView? 
@IBOutlet var Button: UIBarButtonItem! 
@IBOutlet var Bar: UINavigationItem! 

//Other Variables 
var varView = Int() 


    override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib.\ 





    if revealViewController() != nil { 

     Button.target = revealViewController() 
     Button.action = #selector(SWRevealViewController.revealToggle(_:)) 

    } 


    self.view.backgroundColor = UIColor(red: 50/255.0, green: 132/255.0, blue: 255/255.0, alpha: 1.0) 




    BTN.alpha = 1.0 
    BTN4.alpha = 0 


} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 


@IBAction func BTNClicked(sender: AnyObject) { 

    UIView.animateWithDuration(1.0, animations: ({ 


     self.BTN2.transform = CGAffineTransformMakeTranslation(0, -90) 
     self.BTN3.transform = CGAffineTransformMakeTranslation(0, -180) 
     self.BTN4.transform = CGAffineTransformMakeTranslation(0, 0) 
     self.BTN.alpha = 0 
     self.BTN4.alpha = 1.0 



    })) 
} 


@IBAction func BTNClickedAgain(sender: AnyObject) { 

    UIView.animateWithDuration(1.0, animations: ({ 


     self.BTN2.transform = CGAffineTransformMakeTranslation(0, 0) 
     self.BTN3.transform = CGAffineTransformMakeTranslation(0, 0) 
     self.BTN4.transform = CGAffineTransformMakeTranslation(0, 0) 
     self.BTN.alpha = 1.0 
     self.BTN4.alpha = 0 



    })) 
} 

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){ 

    if(editingStyle == UITableViewCellEditingStyle.Delete){ 
     taskMgr.tasks.removeAtIndex(indexPath.row) 
     tbl?.reloadData(); 
    } 
} 

override func viewWillAppear(animated: Bool) { 
    tbl?.reloadData(); 
} 



func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 
    return taskMgr.tasks.count 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> 
    UITableViewCell{ 

     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "test") 

     cell.textLabel?.text = taskMgr.tasks[indexPath.row].name 
     cell.detailTextLabel?.text = taskMgr.tasks[indexPath.row].desc 
     cell.detailTextLabel?.text = taskMgr.tasks[indexPath.row].date 
     return cell 
} 

はまた、ここに私のAddPlan.swiftを見て、私はViewControlelr.swiftでUITableViewCellsにデータを追加する場所これは、次のとおりです。

class addPlan: UIViewController, UITextFieldDelegate { 


var time: Int = 6 


@IBOutlet var txt: UITextField! 

@IBOutlet var txt2: UITextField! // This is the data text, I want this to be on the left side of the UITableViewCell. 
@IBOutlet var txt1: UITextField! 
@IBOutlet var Button02: UIBarButtonItem! 

override func viewDidLoad() { 

    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(addPlan.dismissKeyboard)) 
    view.addGestureRecognizer(tap) 

    self.txt.delegate = self; 
    self.txt1.delegate = self; 
    self.txt2.delegate = self; 




    if revealViewController() != nil { 

     Button02.target = revealViewController() 
     Button02.action = #selector(SWRevealViewController.revealToggle(_:)) 

    } 


} 

func textFieldShouldReturn(textField: UITextField) -> Bool { 
    self.view.endEditing(true) 
    return false 
} 

func dismissKeyboard() { 
    //Causes the view (or one of its embedded text fields) to resign the first responder status. 
    view.endEditing(true) 
} 


@IBAction func ClickedforSelection(sender: UIButton) { 
    taskMgr.addTask(txt.text!, desc: txt1.text!, date: txt2.text!) 
    self.view.endEditing(true) 
    txt.text = "" 
    txt1.text = "" 
    txt2.text = "" // This is the data text 


} 
} 
+0

テーブルビューセルの特定のデザインが必要な場合は、カスタム 'UITableViewCell'サブクラスを作成し、IBでセルをデザインする必要があります。それは非常に簡単であり、インターネット上に多数のチュートリアルがあります。 –

答えて

0

あなたはあなたのためにUITableViewCellStyle.Value1UITableViewCellStyle.Value2を使用することができますUITableViewCellスタイル。 Table View Styles and Accessory Views

UITableViewCellStyle.Value1から

は青色のテキストに字幕を入れて 行の右側を右揃え。画像は ではありません。

UITableViewCellStyle.Value2

は、青色のメインタイトルを置き、 行の左側からインデントの観点でそれを右揃えながら。字幕は、この時点で の右側の短い距離に配置されます。このスタイルはイメージを許可しません。

+0

ええ、私はそれを探していた。 SubtitleとValue2を同時に使用することはできますか?それは実際に私の本当の質問です。 – AS2345

+0

カスタム 'UITableViewCell'を作成すれば可能です。 –

関連する問題