<i id='sqo7o'><tr id='sqo7o'><dt id='sqo7o'><q id='sqo7o'><span id='sqo7o'><b id='sqo7o'><form id='sqo7o'><ins id='sqo7o'></ins><ul id='sqo7o'></ul><sub id='sqo7o'></sub></form><legend id='sqo7o'></legend><bdo id='sqo7o'><pre id='sqo7o'><center id='sqo7o'></center></pre></bdo></b><th id='sqo7o'></th></span></q></dt></tr></i><div id='sqo7o'><tfoot id='sqo7o'></tfoot><dl id='sqo7o'><fieldset id='sqo7o'></fieldset></dl></div>

    <tfoot id='sqo7o'></tfoot>

  1. <legend id='sqo7o'><style id='sqo7o'><dir id='sqo7o'><q id='sqo7o'></q></dir></style></legend>
  2. <small id='sqo7o'></small><noframes id='sqo7o'>

        <bdo id='sqo7o'></bdo><ul id='sqo7o'></ul>

      在 ObjectiveC 上的代表之间传回信息

      Passing back info between delegates on ObjectiveC(在 ObjectiveC 上的代表之间传回信息)

          <small id='aDRjG'></small><noframes id='aDRjG'>

        • <i id='aDRjG'><tr id='aDRjG'><dt id='aDRjG'><q id='aDRjG'><span id='aDRjG'><b id='aDRjG'><form id='aDRjG'><ins id='aDRjG'></ins><ul id='aDRjG'></ul><sub id='aDRjG'></sub></form><legend id='aDRjG'></legend><bdo id='aDRjG'><pre id='aDRjG'><center id='aDRjG'></center></pre></bdo></b><th id='aDRjG'></th></span></q></dt></tr></i><div id='aDRjG'><tfoot id='aDRjG'></tfoot><dl id='aDRjG'><fieldset id='aDRjG'></fieldset></dl></div>
            <bdo id='aDRjG'></bdo><ul id='aDRjG'></ul>
          • <legend id='aDRjG'><style id='aDRjG'><dir id='aDRjG'><q id='aDRjG'></q></dir></style></legend>
          • <tfoot id='aDRjG'></tfoot>
              <tbody id='aDRjG'></tbody>

              • 本文介绍了在 ObjectiveC 上的代表之间传回信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要在 CameraSessionView 之间传回 NSMutableArray 照片;如何将相机拍摄的照片存储在 NSMutableArray 上,以及 TableViewController 如何将这些照片上传到 DropBox.我正在使用委托和协议,但我尝试的所有方式......都失败了.任何人都可以帮助我.我认为我做错了一些小事.我给你看一些代码:

                I need to pass back an NSMutableArray of photos between a CameraSessionView; how store the photos taken from camera on an NSMutableArray, and a TableViewController how uploads this photos to DropBox. I'm using delegates and protocols, but all the ways I tried... fail. Anyone can help me. I think Im doing some little thing wrong. I show you some code:

                CameraSessionView.h

                CameraSessionView.h

                @class CameraSessionView;
                @protocol CameraSessionViewDelegate <NSObject>
                @optional
                -(void)uploadPhotosFromCamera:(NSMutableArray*)photos;
                @end
                
                @property (nonatomic, weak) id <CameraSessionViewDelegate> delegado;
                

                CameraSessionView.m

                CameraSessionView.m

                @property (nonatomic, strong) NSMutableArray* images;
                
                - (void)onTapOkButton{
                
                    NSLog(@"Save photos");
                
                    if([self.delegado respondsToSelector:@selector(uploadPhotosFromCamera:)])
                    [self.delegado uploadPhotosFromCamera:_images];
                
                    [self onTapDismissButton];
                }
                

                PhotosTableViewController.h

                PhotosTableViewController.h

                @interface PhotosTableViewController : UITableViewController <CameraSessionViewDelegate>
                

                PhotosTableViewController.m

                PhotosTableViewController.m

                @property (nonatomic, strong) CameraSessionView *camera;
                - (void)viewDidLoad
                {
                _camera = [CameraSessionView new];
                [_camera setDelegado:self];
                }
                -(void)uploadPhotosFromCamera:(NSMutableArray*)photos
                {
                    NSLog(@"UPFC");
                    for(int x=0; x < [photos count];x++)
                    {
                        NSLog(@"UPFC...");
                
                        UIImage *foto = [photos objectAtIndex:x];
                
                         if (foto.size.height > 1000 || foto.size.width > 1000)
                             foto = [self imageWithImage:foto scaledToScale:0.15f];
                
                         DBMetadata* datos = [TablaSubidas addFile:pathElemento];
                         NSFileManager *fileManager = [NSFileManager defaultManager];
                         NSData *data = UIImageJPEGRepresentation(foto, 1.0);
                         [fileManager createFileAtPath:[self photoPath:datos] contents:data attributes:nil];
                         [elementosTabla insertObject:datos atIndex:0];
                    }
                
                    [self sincFotos];
                    [self.tableView reloadData];
                }
                

                只希望当我按下 OK 按钮时,照片会发送回 PhotosTableViewController 并上传到 dropbox.

                Only wants that when I press OK button the photos send back to PhotosTableViewController where it would be uploaded to dropbox.

                onTapOKButton 上的 self.delegado 始终为 nil.

                self.delegado on onTapOKButton is always nil.

                看起来很简单,但我无法运行它.如果有人可以帮助我或向我推荐任何教程,我将不胜感激......

                Looks easy but I cant run it. I'm so grateful if anyone could help me or recommend me any tutorial...

                谢谢!!

                推荐答案

                您的 CameraSessionView 实例将在 viewDidLoad 结束后立即从内存中释放.您需要将其存储在 PhotosTableViewController 的属性中,以便保留.

                Your CameraSessionView instance will be released from memory as soon as viewDidLoad ends. You need to store it in a property in PhotosTableViewController so that it is retained.

                您的委托也应该被定义为弱,例如

                Your delegate should also be defined as weak, e.g.

                @property (nonatomic,weak) id< CameraSessionViewDelegate >delegado;
                

                然后在您的 PhotosTableViewController 实现中,您需要实现 -(void)uploadPhotosFromCamera:(NSMutableArray*)photos; 方法.

                Then in your implementation of PhotosTableViewController, you'll need to implement the -(void)uploadPhotosFromCamera:(NSMutableArray*)photos; method.

                由于这个方法被定义为@optional,你应该在调用它之前检查委托是否响应它.

                Also as this method is defined as @optional, you should check if the delegate responds to it before calling it.

                   if([self.delegado respondsToSelector:@selector(uploadPhotosFromCamera:]){
                        [self.delegado uploadPhotosFromCamera:_images];
                   }
                

                如果未实现委托方法,这将防止应用崩溃.

                This will prevent the app from crashing if the delegate method isn't implemented.

                这篇关于在 ObjectiveC 上的代表之间传回信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员

                1. <legend id='7KFn1'><style id='7KFn1'><dir id='7KFn1'><q id='7KFn1'></q></dir></style></legend>
                      <bdo id='7KFn1'></bdo><ul id='7KFn1'></ul>
                        <tbody id='7KFn1'></tbody>

                      <i id='7KFn1'><tr id='7KFn1'><dt id='7KFn1'><q id='7KFn1'><span id='7KFn1'><b id='7KFn1'><form id='7KFn1'><ins id='7KFn1'></ins><ul id='7KFn1'></ul><sub id='7KFn1'></sub></form><legend id='7KFn1'></legend><bdo id='7KFn1'><pre id='7KFn1'><center id='7KFn1'></center></pre></bdo></b><th id='7KFn1'></th></span></q></dt></tr></i><div id='7KFn1'><tfoot id='7KFn1'></tfoot><dl id='7KFn1'><fieldset id='7KFn1'></fieldset></dl></div>
                      <tfoot id='7KFn1'></tfoot>

                          <small id='7KFn1'></small><noframes id='7KFn1'>