2

UITableView大量のデータがあります。そして、私はUITableViewCell毎回次のように作成します:

 UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCellIdentifier]; 

その後UIView、サブビューとして多くのUITableViewCellを追加します。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button addTarget:self action:@selector(onDocumentLogoTapped:) forControlEvents:UIControlEventTouchUpInside];
                button.frame = imageRect;
                button.tag = indexPath.row;
                [cell addSubview:button];

そして、そのように私も追加しUIImageViewます。問題は、UITableViewメモリの問題が原因で、私の速度が非常に遅くなり、アプリケーションがクラッシュすることです。

UITableViewCellsubViewを追加するときに、誰かが私に適切な使用方法を提案できますか?

4

3 に答える 3

4

メソッドでこれを使用しますcellForRowAtIndexPath

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

}
于 2013-02-22T06:25:27.720 に答える
1

次のようにします。

サブビューを追加する前に、まず以前のサブビューを削除してください

for(UIView *sv in [cell.contentView subViews])
{
   [sv removefromsuperview];
}

[cell.contentView addSubview:button];

このヘルプを願っています!

于 2013-02-22T06:36:40.743 に答える
0

カスタムセルを使用すると、このメソッドを次のように使用できます。

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

            NSArray *nib;
        static NSString *cellIdentifier= @"cell";

        UITableViewCell *theCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];


        if(theCell== nil)
        {
            {
                nib = [[NSBundle mainBundle] loadNibNamed:@"<your custom cell xib name>" owner:self options:nil]; 
            }
            theCell = [nib objectAtIndex:0];

             theCell.selectionStyle = UITableViewCellSelectionStyleBlue;
        }

        UIImageView *imageView=(UIImageView*)[[theCell contentView] viewWithTag:101];
//assuming it has a image view with tag 101 you can use any thing

}
于 2013-02-22T06:21:13.793 に答える