当我从 -[MyController tableView:willDisplayCell:forRowAtIndexPath:] 获取代码并将其放入我的函数 SubmitAll 中时,我的方法出现了问题。
-(void)submitAll: (id)sender
{
NSArray *data_webs;
if (indexPath.section == 0) { "problem here"
data_webs = [mcq_question data_webs];
} else {
data_webs = [structured_question data_webs];
}
data_web *current_data ;
current_data = [data_webs objectAtIndex:indexPath.row]; "problem here"
NSString *is_submited = [NSString stringWithFormat:@"%@",[current_data content_2]];
NSLog(@"%@", [current_data the_id]);
}
- 自定义函数中indexPath.row的等效值是多少?
- if (indexPath.section == 0) 中正确的脚本是什么?
我使用此函数的目的是列出 [current_data the_id] 内的所有值或放入数组中并刷新页面。
我不确定我是否遵循了正确的方法,我只是 IOS 的新手。
最佳答案
不确定您在哪里调用提交所有方法。但试试这样
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self submitAll:[indexPath row]]
}
-(void)submitAll:(NSInteger) row
{
NSArray *data_webs;
if (row == 0)
{
data_webs = [NSArray arrayWithArray:[mcq_question data_webs]];
//Assuming [mcq_question data_webs] retuns NSArray
}
else
{
data_webs = [NSArray arrayWithArray:[structured_question data_webs]];
}
data_web *current_data ;
current_data = [data_webs objectAtIndex:row]; "problem here"
NSString *is_submited = [NSString stringWithFormat:@"%@",[current_data content_2]];
NSLog(@"%@", [current_data the_id]);
}
关于iphone - 自定义函数 "indexpath",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18695995/