0

カスタムの tablview_cell を作成し、テーブルビューのセル内にボタンを追加しました。シミュレーターで実行しているときは、うまく機能しています。しかし、デバイスではスクロールにほとんど固執しません。この問題を解決する方法はありますか、教えてください。

事前に感謝

私はこれを試します:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 250;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"Cell+Identifier";
    Custom_Cell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Custom_Cell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        [cell.btn1 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn2 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn3 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn4 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn5 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn6 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn7 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn8 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn9 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn10 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn11 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn12 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];


    }

    cell.label.text = [NSString stringWithFormat:@"%d",indexPath.row];
    return cell;
}


-(void)selected_files:(id)sender
{
     View_2 *v2 = [[View_2 alloc]init];
    [self.navigationController pushViewController:v2 animated:YES];



}

以下では、参考のために Custom_Cell について言及しました。

ここに画像の説明を入力

4

1 に答える 1

0

これを試して、

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *cellIdentifier=@"cell";

    Custom_Cell *cell = (Custom_Cell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil)
    {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"Custom_Cell" owner:self options:nil];

        for (id currentObject in topLevelObjects)
        {
            if ([currentObject isKindOfClass:[UITableViewCell class]])
            {
                cell =  (Custom_Cell *) currentObject;
                break;
            }
        }
    }

 [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

[cell.btn1 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn2 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn3 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn4 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn5 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn6 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn7 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn8 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn9 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn10 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn11 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btn12 addTarget:self action:@selector(selected_files:) forControlEvents:UIControlEventTouchUpInside];
 cell.label.text = [NSString stringWithFormat:@"%d",indexPath.row];

    return cell;

}
于 2013-10-25T06:31:14.300 に答える