iphone - 自定义函数 "indexpath"

标签 iphone ios function uitableview

当我从 -[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/

相关文章:

javascript - 多次更改 onclick() 函数(背景图像更改)

ios - ideviceinstaller 失败并显示 "Could not connect to lockdownd. Exiting."

ios - `-fembed-bitcode` 尝试存档应用程序时出错

ios - 尝试创建一个 Xcode Objective-C 函数来记录我的 UIView 内容的视频捕获并保存到手机

ios - Swift 2.1 - 在委托(delegate)方法调用上展开 Optional 时意外发现 nil

ios - Xcode 项目变坏了 - 忘记设备并任意取消构建

ios - 在 Swift 中检查 UIContentContainer 是否为 ViewContoller

javascript - 单击按钮时加载数据

iphone - 禁用自定义选择器中的特定行

python - python中通过函数列表列表