【问题标题】:Display Photo from UIImageView in another view在另一个视图中显示来自 UIImageView 的照片
【发布时间】:2013-10-26 18:22:27
【问题描述】:

我有一个类,其中包含 tableView 的信息

    @interface Tricks : NSObject

   @property(strong, nonatomic) UIImageView *trickPhoto;
   @property(strong, nonatomic) NSString *trickName;
   @property(nonatomic) BOOL landed;

   +(NSMutableArray *)trickList;

@结束

在这个类中,当我点击保存时,它会在 tableview 中创建一个单元格

-(IBAction)saveAction:(id)sender

    Tricks *trick = [[Tricks alloc]init];
        trick.trickName = self.trickLabel.text;
        trick.trickPhoto.image = self.trickPhotoTake.image;
        [[Tricks trickList]addObject:trick];

从 tableViewCell 推送的 detailViewController 我想显示技巧和照片的名称,但它只显示名称。 使用我知道的断点,UIImage 属性中有一个名为trickPhoto 的值,但没有显示图片。 感谢您的建议

【问题讨论】:

    标签: ios objective-c uitableview uiimageview


    【解决方案1】:

    如果你使用 Storyboards,你需要使用:

     - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    

    any 属性只存在于创建它的类中。如果您在 ViewControllr 中并使用名为 @"image.png" 的图像设置 DetailViewController 的 UIImageView 属性,则 DetailViewController 的该属性仅存在于 ViewController 中。

    试试:

     - (void)prepareForSegue:(UIStoryboardSegue    
     *)segue sender:(id)sender
    if ([segue.destinationViewController        
     isKindOfClass:[DetailViewController class]]) {
        viewController = 
         segue.destinationViewController;
        if ([segue.identifier 
    isEqualToString:@"____enterSegueIdentifier____"])
    {
            detailViewController.trickPhoto.image = 
         [UIImage imageNamed:@"______"];
        }
    }
     }
    

    【讨论】:

    • detailViewController.trickPhoto.image = trick.trickPhoto.image;图片仅在视图中,我想从那里加载它
    【解决方案2】:

    在 detailViewController 中,您可以像这样从另一个 viewController 调用 extern 属性:

      extern UIImageView *trickPhoto;
    

    将下面的代码放在导入之后。

          @interface detailViewController () 
    

    【讨论】:

    • 您能否详细说明为什么您认为需要extern
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2021-12-06
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多