Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UITableView中按标记选择textfield时出错_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 在UITableView中按标记选择textfield时出错

Ios 在UITableView中按标记选择textfield时出错,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个带有文本字段的UITableView,我创建了一个命令,在该命令中,您可以在我的表格中再添加一行,从而在表格中创建另一个文本字段,我通过输入特定标记区分每个文本字段,如下所示: - (UITableViewCell *)tableView:(UITableView *)tableView2 cellForRowAtIndexPath:(NSIndexPath *)indexPath {//Ja explicado anteriormente static NSString *s

我有一个带有文本字段的UITableView,我创建了一个命令,在该命令中,您可以在我的表格中再添加一行,从而在表格中创建另一个文本字段,我通过输入特定标记区分每个文本字段,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView2 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{//Ja explicado anteriormente

    static NSString *simpleTableIdentifier = @"ComissoesTableViewCell";//Ja explicado anteriormente

    ComissoesTableViewCell *cell = (ComissoesTableViewCell *)[tableView2 dequeueReusableCellWithIdentifier:simpleTableIdentifier];//Ja explicado anteriormente

    if (cell == nil){//Ja explicado anteriormente

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ComissoesTableViewCell" owner:self options:nil];//Ja explicado anteriormente

        cell = [nib objectAtIndex:0];//Ja explicado anteriormente
    }

    cell.data.tag = indexPath.row;

Return Cell;

}
下面是在表中插入新行的命令,仅当用户单击现有视图中的按钮时才会调用此方法:

- (void)viewDidLoad
{
    [super viewDidLoad];

    iArray = [[NSMutableArray alloc] init];

    numeroCampos = 1;
    [tableView reloadData];

}

-(void)AdicionarField{

    iArray = [[NSMutableArray alloc] init];

    numeroCampos++;

    for(int x=0;x<numeroCampos;x++){

        [iArray addObject:[self getByTag:x]];

    }
-(void)viewDidLoad
{
[超级视图下载];
iArray=[[NSMutableArray alloc]init];
numeroCampos=1;
[tableView重新加载数据];
}
-(无效)阿迪西奥纳菲尔德{
iArray=[[NSMutableArray alloc]init];
numeroCampos++;

对于(int x=0;xException stack trace告诉您问题所在,您正试图将nil对象插入数组,这会导致未捕获异常,请在将任何对象插入数组之前检查nil。@IDIDU!我看到了问题,问题出在我的表中!我的表视图有990x550像素,当我们插入超过9行时,表视图将自动创建一个滚动条,用户看不到textField tag=1!这会导致问题,因为textField tag=1现在已禁用,但原因是什么?我如何解决这个问题?您似乎正在使用uitableviewcell(ComissoSettableviewcell)存储数据。getByTag方法看起来效率极低(它具有双重嵌套的for循环,方法本身在for循环中被调用)。UITableView(或任何视图)的数据源应独立保存在模型对象中,并以允许快速访问的方式构造(NSDictionary、NSArray等).Well@Anna,目前我能看到的唯一解决方案是,当tableView中的行数变为9时,一旦我的tableView插入到scrollView中,我就增加了tableView的高度,因此我增加了表格的高度,并相对于行数进行了滚动
-(NSString *)getByTag:(NSInteger)myTag {

    NSLog(@"Get By Tag -> %d",myTag);

    NSString *texto = @"null";

    NSMutableArray *cells = [[NSMutableArray alloc] init];
    for (NSInteger j = 0; j < [tableView numberOfSections]; ++j)
    {
        for (NSInteger i = 0; i < [tableView numberOfRowsInSection:j]; ++i)
        {
            [cells addObject:[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]]];
        }
    }

    for (ComissoesTableViewCell *cell in cells)
    {
        if (cell.data.tag == myTag){
            texto = [NSString stringWithFormat:@"%@",cell.data.text];

        }
    }

    return texto;
}