var accountId = String()
var dataRows = [NSDictionary]()
var grandChilds = [NSDictionary]()
var dataOfGrandChilds = NSMutableDictionary()
override func viewDidLoad() {
super.viewDidLoad()
print("loaded hie \(accountId)")
let request = SFRestAPI.sharedInstance().requestForQuery("SELECT Name,Id FROM Account where parentid='\(self.accountId)'");
//SFRestAPI.sharedInstance().send(request, delegate: self);
SFRestAPI.sharedInstance().sendRESTRequest(request, failBlock: {error in print(error)}, completeBlock: { responce in print(responce)
self.dataRows = responce["records"] as! [NSDictionary]
var counter = 0;
for i in self.dataRows
{
let requestForGrandChilds = SFRestAPI.sharedInstance().requestForQuery("select Name,Id from Account where parentid='\(i["Id"]!)'")
SFRestAPI.sharedInstance().sendRESTRequest(requestForGrandChilds,
failBlock:
{
error in print(error)
print("error block")
},
completeBlock:
{
responceChild in
self.grandChilds = responceChild["records"] as! [NSDictionary]
self.dataOfGrandChilds["\(counter)"] = self.grandChilds
print(self.dataOfGrandChilds)
counter += 1
print("control still in inner competion block")
dispatch_async(dispatch_get_main_queue(),
{ () -> Void in
print("Control came to main queue")
self.tableView.reloadData()
})
})
}
})
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
if(dataOfGrandChilds.count > 0 ){
return dataOfGrandChilds.count
}
return 1
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return dataRows[section]["Name"] as? String
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("toViewChilds", forIndexPath: indexPath)
print(indexPath.section)
print(dataOfGrandChilds["\(indexPath.section)"])
if let tempData = dataOfGrandChilds["\(indexPath.section)"]
{
cell.textLabel?.text = tempData[indexPath.row]["Name"] as? String
}
return cell
}
在第一个请求中,我正在尝试获取Id的直接子帐户。在第一个请求的完成块中,我正在尝试获取大孩子帐户。 dataRows包含节标题的数据(这是直接的子名称)。 dataOfGrandChilds是一个字典,它将段号作为键,相应的grandChilds数组作为其值。
在重新加载我的tableView时,我只能显示第1个子节点而不显示第二节子节点。请帮助找到解决方案。
我得到的错误是
2016-06-07 11:10:30.764 iCRM [67964:11218133] ***终止app到期 未被捕获的异常'NSRangeException',原因:' - [__ NSCFArray objectAtIndex:]:index(1)超出bounds(1)'
答案 0 :(得分:1)
foreach($_FILES as $file) {
if (move_uploaded_file($file['tmp_name'], $uploaddir.basename($file['name']))) {
$files[] = $uploaddir.basename($file['name']);
} else {
$error = true;
}
}
完成的更改是: