关于IOS 中使用 UIViewController 生成表单,提交表单的问题. 希望大家给点思路.

我现在的需求如下,希望大家给点思路.

我有一个表单,需要提交更新

clipboard.png

点击修改跳转到下面的界面

clipboard.png

这个页面的代码如下: 我取得网络上的数据后生成字典,然后展示在页面上.

//
//  WoModifyDataViewController.swift
//  yuanyuan
//
//  Created by 刘少晨 on 15/9/27.
//  Copyright (c) 2015年 lsc. All rights reserved.
//

import UIKit
import Alamofire
class WoModifyDataViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
    //初始化用户类
    var YYUser = User_YuanYuan()
    // 初始化URL类
    var YYURL = URL_YuanYuan()
    
    //资料列表
    @IBOutlet weak var dataList: UITableView!
    
    var dataListC = [Dictionary<String,String>]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        dataList.delegate = self
        dataList.dataSource = self
        
        //如果没有数据,隐藏ListTableView下划线
        dataList.tableFooterView = UIView.new()
        dataList.separatorColor = UIColor(red: 239/255, green: 239/255, blue: 244/255, alpha: 1.0)
        Alamofire.request(.GET, YYURL.userDetailsDataHost, parameters: ["uid":1]).responseJSON() { (_, _, jsonData, _) -> Void in
            println(jsonData)
            if var j = jsonData as? NSDictionary{
                self.dataListC.append(["Project":"自我介绍","Value":j.valueForKey("bio") as! String])
                self.dataListC.append(["Project":"公司","Value":j.valueForKey("company") as! String])
                self.dataListC.append(["Project":"GitHub","Value":j.valueForKey("github") as! String])
                self.dataListC.append(["Project":"主页","Value":j.valueForKey("site") as! String])
                println(self.dataListC)
                self.dataList.reloadData()
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cellid = "FujinID"
        var index = indexPath.row
        
        var cell:Wo_ModifyDataTableViewCell? = dataList.dequeueReusableCellWithIdentifier(cellid) as? Wo_ModifyDataTableViewCell
        if(cell == nil){
            cell = Wo_ModifyDataTableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: cellid)
        }
        
        cell?.Project?.text = self.dataListC[indexPath.row]["Project"]
        cell?.Value!.text = self.dataListC[indexPath.row]["Value"]
        
        return cell!
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
        return 40.0
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        //println(self.abc.count)
        return self.dataListC.count
    }

    @IBAction func saveData(sender: AnyObject) {
        println(dataListC)
    }
}

现在的问题是,我如何取这些修改后的值?

阅读 4.9k
4 个回答

问题处在使用问题的方式,LZ的方式无法有效使用iOS的strong特性,来得到跨页面修改值的效果.建议按一下步骤执行:
1.定义一个 名为Person的model,用此类的实例来存储请求到的数据,而不是直接使用数组.
2.A页面此时的数据源应从 数组,改为 Person类型.
3.点击"修改",把 Person 直接传递给 下一界面,如B.
4.B界面修改后,返回时,直接把B页面的值赋给传进的model.
5.在A界面的 viewWillAppear 方法里,调用 tabelView的 reloadData 方法即可.

刷新一下不好么?

在你输入时修改 修改页面的数据源,保存就上传修改后的,返回就什么都不做

新手上路,请多包涵

既然可以输入,那么就是textview类的,你可以通过代理获取每次是在哪个里面输入的,这些信息你可以每个字段给个标识就可以了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题