IOS UITableView "Delete"按钮不出现

标签 ios objective-c iphone uitableview button

我正在开发应用程序,用户可以在其中创建带有附件的帖子。对于附件,我使用了 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

我已经尝试了所有可能的解决方案,但无法坚持下去,请帮忙

最佳答案

解决了! 问题是在横向模式下,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 大小。

关于IOS UITableView "Delete"按钮不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13992360/

相关文章:

iphone - 使用 AVAssetReader 和 ARC 绘制波形

ios - 为什么 CustomStringConvertible 协议(protocol)不适用于 Int?

ios - 如何判断Apple Watch型号?

ios - Facebook 号召性用语 ios 应用程序链接

iOS : Not receiving facebook App invites

ios - 从 Storyboard 中实例化几个可拖动的图 block - 附上测试代码和屏幕截图

ios - 在 React Native 中禁用 WebView 中的缩放或 react-native-wkwebview

objective-c - AWS IOS SDK 1.7.0 -> 架构 armv7s 的 undefined symbol :

objective-c - 如何在透明 NSWindow 中区分 mouseDown 事件和 mouseDragged 事件

iphone - 此应用程序在 ios 5.0 下开发并运行良好,但在 ios 4.3 下崩溃