我需要从相同的NSMutableArray
中获取2个输入值,例如textfield 1和textfield 2 [score 1,score 2],并将这些值添加到字典中并将这些字典数据添加到- (void)textFieldDidEndEditing:(UITextField *)textField{
UITableViewCell *cell = (UITableViewCell*) textField.superview.superview;
NSIndexPath *txtIndPath = [tblMonthlyPerformanceReport indexPathForCell:cell];
MonthlyPerformanceQuestions * question;
if (txtIndPath.section==0)
{
question = [[HSEAppData appData].arrayMonthlyGeneralQustion objectAtIndex:txtIndPath.row];
}
if (txtIndPath.section==1)
{
question = [[HSEAppData appData].arrayMonthlyLeadQustion objectAtIndex:txtIndPath.row];
} if (txtIndPath.section==2)
{
question = [[HSEAppData appData].arrayMonthlyLagQustion objectAtIndex:txtIndPath.row];
}
NSLog(@"%@ , %@",question.QuestionId, question.Question);
NSMutableDictionary *userDictionary=[[NSMutableDictionary alloc]init];
[userDictionary setObject:question.QuestionId forKey:@"question"];
if (textField.tag==10001)
{
[userDictionary setObject:textField.text forKey:@"score1"];
}
if (textField.tag==10002)
{
[userDictionary setObject:textField.text forKey:@"score2"];
}
[scoreMutableArray addObject:userDictionary];
我在下面的代码中使用了文本字段委托方法..
{
question = a5k0k0000004kxsAAA;
score2 = 5;
}
我收到了回复
{
"question": "a5k0k0000004kxnAAA",
"score1": "20",
"score2": "20"
}
我将数据放在得分1上,但数据得分为2 我需要像这样的字典数据
/*CREATE TOP AND BOTTOM CLAUSES*/
/*Top Clauses*/
const addClauseTop = document.querySelector('#addClauseTop');
var targetClauseElement;
var addDetail = document.getElementById('addDetail');
addDetail.addEventListener('focusin', function(e) {
createDetail(e.relatedTarget);
});
window.addEventListener('mouseup',function(e) {
if ( e.currentTarget != addDetail ) {
addDetail.style.display='none';
}
});
var firstTopClause = document.getElementsByClassName('clause')[0];
firstTopClause.addEventListener('click', function(e) {
addDetail.style.display='inline-block';
});
var firstBottomClause = document.getElementsByClassName('clauseDivReverse')[0];
firstBottomClause.addEventListener('click', function(e) {
addDetail.style.display='inline-block';
});
addClauseTop.addEventListener('click',function(e){
e.preventDefault();
//Get Divs-Overlay
const topDivs = document.querySelector('#topClauses');
const bottomDivs = document.querySelector('#bottomClauses');
// Create Elements
const clauseDiv = document.createElement('div');
const clauseText = document.createElement('input');
const clauseStroke = document.createElement('div');
// // //Give Style
clauseDiv.classList.add('clauseDiv');
clauseDiv.addEventListener('click', function(e) {
addDetail.style.display='inline-block';
});
clauseText.classList.add('clause');
clauseText.setAttribute("id", "clause");
clauseStroke.classList.add('strokeClause');
//
// // Append to document
clauseDiv.appendChild(clauseText);
clauseDiv.appendChild(clauseStroke);
topDivs.appendChild(clauseDiv);
document.body.appendChild(topDivs);
document.body.appendChild(bottomDivs);
})
/*BOTTOM Clauses*/
const addClauseBottom = document.querySelector('#addClauseBottom');
addClauseBottom.addEventListener('click',function(e){
e.preventDefault();
//Get Divs-Overlay
const topDivs = document.querySelector('#topClauses');
const bottomDivs = document.querySelector('#bottomClauses');
// Create Elements
const clauseDiv = document.createElement('div');
clauseDiv.addEventListener('click', function(e) {
targetClauseElement = e.currentTarget;
addDetail.style.display='inline-block';
});
const clauseText = document.createElement('input');
const clauseStroke = document.createElement('div');
// // //Give Style
clauseDiv.classList.add('clauseDivReverse');
clauseText.classList.add('clauseReverse');
clauseText.setAttribute("id", "clauseReverse");
clauseStroke.classList.add('strokeClauseReverse');
//
// // Append to document
clauseDiv.appendChild(clauseText);
clauseDiv.appendChild(clauseStroke);
bottomDivs.appendChild(clauseDiv);
document.body.appendChild(bottomDivs);
})
/***********/
//Create a addDetail
function createDetail(target){
var mainColumn = target.parentElement;
var strokeColumn = mainColumn.children[1];
// Create Elements
var levelOneDiv = document.createElement('div');
var levelOneText = document.createElement('input');
if ( mainColumn.classList.contains('clauseDiv') ) {
levelOneDiv.classList.add('levelOneClauseReverse');
levelOneText.classList.add('levelOneTextReverse');
//I thought you have not completed your style yet, like something levelOneClause class
} else {
levelOneDiv.classList.add('levelOneClauseReverse');
levelOneText.classList.add('levelOneTextReverse');
}
levelOneDiv.appendChild(levelOneText);
strokeColumn.appendChild(levelOneDiv);
}
请帮帮我
答案 0 :(得分:0)
将Dictionary作为全局变量。在字典中添加每个值,然后在添加字典到数组时检查字典的数量(如果是3)则将字典添加到数组并在将字典添加为空后添加字典。