0

ユーザーが添付ファイル付きの投稿を作成できるアプリを開発しています。アタッチメントについては、次の方法UITableViewで水平モードで使用および回転しました。viewDidLoad

// Rotates the view.
    CGAffineTransform transform = CGAffineTransformMakeRotation(-1.5707963);
    imageAttachmentTableView.transform = transform;

ユーザーがフォトライブラリから画像を選択すると、UITableViewのimageViewに読み込まれます。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    CGAffineTransform transform = CGAffineTransformMakeRotation(1.5707963);
    cell.imageView.transform = transform;
    cell.imageView.frame = CGRectMake(0, 0, 110, 110);

    cell.imageVenter image description hereiew.image = [imageAttachments objectAtIndex:indexPath.row];
    return cell;                  
}

cell.imageView画像が実際の向きで見えるように、再び反対方向に回転します

UITableViewは編集モードで作成されているため、画像が読み込まれるときに、シングルタップで画像を削除することもできます。

- (void)viewWillAppear:(BOOL)animated {
    [imageAttachmentTableView setEditing: YES animated: YES];
}

また、デフォルトの「削除」テキストを「X」に変更しました

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"X";
}

次の画面のように、ユーザーが「-」ボタンをタップすると、コードはポートレートモードで完全に機能します。「X」が表示されます。

http://img5.imageshack.us/img5/1125/screenshot20121221at742.png

問題は横向きモードで、(-)ボタンは表示されますが、「X」ボタンは表示されません。 http://img833.imageshack.us/img833/6305/screenshot20121221at747.png

私はすべての可能な解決策を試しましたが、スティックを作ることができませんでした、助けてください

4

1 に答える 1

1

解決しました!問題は、ランドスケープモードで、UITableViewCellのサイズと[削除]ボタンのフレームが変更されたためUITableViewCell、カスタムクラスでサブクラス化することでした。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    OMAttachmentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[OMAttachmentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    CGAffineTransform transform = CGAffineTransformMakeRotation(1.5707963);
    cell.imageView.transform = transform;
    cell.imageView.frame = CGRectMake(0, 0, 110, 110);

    cell.imageView.image = [imageAttachments objectAtIndex:indexPath.row];
    return cell;                  
}

私のOMAttachmentCellクラスでは、次のメソッドを実装しました。

-(void) willTransitionToState:(UITableViewCellStateMask)state
{
    [super willTransitionToState:state];

    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {

        for (UIView *subview in self.subviews) {

            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
                UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
                CGRect f = deleteButtonView.frame;
                f.origin.x = 0;
                f.origin.y = 0;
                f.size.width = 30;
                f.size.height = 34;

                CGRect sf = self.frame;
                sf.size.width = 110;
                sf.size.height = 110;

                deleteButtonView.frame = f;
                self.frame = sf;
            }
        }
    }
}

ここでは、削除ボタンのフレームとTableCellのサイズを更新しました。

于 2012-12-28T08:16:17.457 に答える