2016-05-13 8 views
1

image of iOS simulator window on iphone retina 4 inch iOS7ラベルとUISwitchをカスタムセルに配置するにはどうすればよいですか?私が調査していると私は理解していないんだけど、それはこの私がこの回答を複数回ググまし

以下の絵と私はどちらか動作していないか、意味がありません見つけることだと類似しています私に。誰もがこれを打つと私を助けることができますか?この問題に何時間もぶつかった。

+0

ここをクリックして画像の説明を入力してください。 –

+2

これまでに何を試しましたか?これまでに行ったことをあなたの質問に反映させ、あなたが抱えている正確な問題を説明してください。 – rmaddy

+0

カスタムセルを作成しようとしましたか? –

答えて

0

働いていないとはどういう意味ですか?ストーリーボードのビューコントローラーでテーブルビューをドラッグし、次にUITableViewCellをドラッグし、UILabelとUISwitchを続けてください。スクリーンショットを添付しました。

enter image description here

、tableviewcellのカスタムクラスを作成してドラッグし、クラスファイルの.Hにスイッチし、ラベルをリンクし、それはあなたが、それはそのような単純な作業を取得しますそれです。

enter image description here

のUITableViewの「データソース」と「デリゲート」メソッドのをリンクすることを忘れないでください。

0
のUITableViewのデリゲートメソッドでCellForRowAtIndexPathへ

後藤

それはあなたUILabelのために

のために働く、このコードを追加:UISwitchため

var newLabel = UILabel(frame: CGRectMake(280.0, 14.0, 300.0, 30.0)) //make frame according to your need 
newLabel.text = newData[indexPath.row] 
newLabel.tag = 1 

var switchView: UISwitch = UISwitch(frame: CGRectZero) 
aCell.accessoryView = switchView 
switchView.setOn(false, animated: false) 
switchView.addTarget(self, action: "switchChanged:", forControlEvents: .ValueChanged) 
0

することはできdownloadカスタムを表ビューのセル。

ラベルとスイッチがあります。

enter image description here

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let cell : CustomCell! = tableView.dequeueReusableCellWithIdentifier("ID_CustomCell", forIndexPath: indexPath) as! CustomCell 

    cell.selectionStyle = UITableViewCellSelectionStyle.None 

    cell.lblData.text = myArray.objectAtIndex(indexPath.row).valueForKey("Data") as? String 

    if let str = myArray.objectAtIndex(indexPath.row).valueForKey("Data") as? String 
    { 
     cell.lblData.text = str as String 

    } 

    cell.switch1.tag = indexPath.row 

    cell.switch1.addTarget(self, action: "switchChanged:", forControlEvents: UIControlEvents.ValueChanged) 


    return cell 

} 

func switchChanged(mySwitch: UISwitch) { 

    let no = mySwitch.tag 
    let selectedIndex = NSIndexPath(forRow: no, inSection: 0) 

    let currentCell : CustomCell = table1.cellForRowAtIndexPath(selectedIndex)! as! CustomCell 

    if currentCell.switch1.on 
    { 
     currentCell.switch1.setOn(true, animated: true) 
    } 
    else 
    { 
     currentCell.switch1.setOn(false, animated: true) 
    } 

} 

switchChanged方法では、あなたのアレイの状態を変更することができます。後でその配列を利用することができます。

すべて最高です。

更新

cellForRowAtIndexPathとswitchChangedとだけ更新され、ダウンロードコード。

関連する問題

 関連する問題