从故事板中展开可防止调用代理

时间:2017-08-30 19:58:36

标签: ios objective-c delegates segue

我有一个UIViewController有几个segues深度,当使用完成时,应该unwind并将它们带回DashboardViewController。

我在信息中心中创建了unwindToDashboard方法,并将一个按钮连接到Exit中的FinishViewController。因此,点击它将触发展开动作。

工作正常。

但我需要从FinishViewController传回数据到仪表板。

所以我为ProcessDataDelegate创建了一个委托FinishViewController,并使仪表板符合它。

但是,控制板中的委托方法是 NOT 调用。

谁能告诉我我做错了什么?

DashboardViewController.m

#import "FinishViewController.h"

@interface DashboardViewController () <ProcessDataDelegate>{
    FinishViewController *fm;
}
@end

@implementation DashboardViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    if(!fm){
        fm = [[FinishViewController alloc] init];

    }

    fm.delegate = self;
}

- (IBAction)unwindToDashboard:(UIStoryboardSegue *)unwindSegue {
//empty
}

#pragma mark PROTOCOL METHODS

-(void) didFinishWithResults:(NSDictionary*) dictionary{
    NSLog(@"Dashboard method called didFinishWithResults");
}

@end

FinishViewController.h

@class FinishViewController;
@protocol ProcessDataDelegate <NSObject>
    @required
    - (void) didFinishWithResults: (NSDictionary*)dictionary;
@end

@interface FinishViewController : UIViewController 
@property (nonatomic, weak) id <ProcessDataDelegate>  delegate;
@end

FinishViewController.m

@interface FinishViewController () 
@end

@implementation FinishViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"fired via the button to the exit--- Segue: %@", [segue identifier]);
    [delegate didFinishWithResults:nil ];
}

@end

1 个答案:

答案 0 :(得分:1)

You need pass your delegate in The result looks like this: Name Start_time End_time 1 John 5/6/15 6:30 2 John2 5/7/15 4:30 5/6/15 8:30 3 Ben 5/8/15 2:30 5/7/15 7:25 4 Ben2 5/9/15 3:10 5/8/15 4:10 I want it to look like this: Name Start_time End_time 1 John 5/6/15 6:30 5/6/15 8:30 2 John2 5/7/15 4:30 5/7/15 7:25 3 Ben 5/8/15 2:30 5/8/15 4:10 4 Ben2 5/9/15 3:10 5/9/15 5:20 method of your function Canvas(width, height, camera) { this.canvas = document.createElement('canvas') this.canvas.width = width this.canvas.height = height this.context = this.canvas.getContext('2d') this.camera = camera this.image = undefined document.body.appendChild(this.canvas) } Canvas.prototype.generateBackground = function(worldWidth, worldHeight) { let cvs = document.createElement('canvas') let ctx = cvs.getContext('2d') cvs.width = worldWidth cvs.height = worldHeight let boxSize = 50 for(let i = 0; i <= worldWidth; i += boxSize) { ctx.moveTo(i, 0) ctx.lineTo(i, worldHeight) ctx.stroke() } for(let j = 0; j <= worldHeight; j+= boxSize) { ctx.moveTo(0, j) ctx.lineTo(worldWidth, j) ctx.stroke() } let dataUrl = ctx.canvas.toDataURL("image/png"); let img = new Image() img.src = dataUrl this.img = img ctx = null } Canvas.prototype.drawBackground = function() { let canvas = this.canvas let context = this.context let xPos = this.camera.xPos let yPos = this.camera.yPos let img = this.img context.clearRect(0, 0, canvas.width, canvas.height) context.drawImage(img, xPos, yPos, canvas.width, canvas.height, 0, 0, canvas.width, canvas.height) } let c = new Canvas(500, 500, {xPos: 0, yPos: 0}) c.generateBackground(10000, 10000) setInterval(() => c.drawBackground(), 15) , there get the #include <stdio.h> #include <thrust/host_vector.h> #include <thrust/device_vector.h> using thrust::host_vector; using thrust::device_vector; #define BLOCKSIZE 512 __global__ void child(int* a) { if (threadIdx.x == 0 && blockIdx.x == 0) a[0]++; } __global__ void parent(int* a) { if (threadIdx.x == 0 && blockIdx.x == 0) child<<<gridDim, blockDim>>>(a); } #define NBLOCKS 1024 #define NTHREADS 1024 #define BENCHCOUNT 1000 template<typename Lambda> void runBench(Lambda arg, int* rp, const char* name) { // "preheat" the GPU for (int i = 0; i < 100; i++) child<<<dim3(NBLOCKS,1,1), dim3(NTHREADS,1,1)>>>(rp); cudaEvent_t start, stop; float rtime = 0.0f; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start, 0); for (int i = 0; i < BENCHCOUNT; i++) arg(); cudaEventRecord(stop, 0); cudaEventSynchronize(stop); cudaEventElapsedTime(&rtime, start, stop); printf("=== %s ===\n", name); printf("time: %f ms\n", rtime/BENCHCOUNT); fflush(stdout); cudaEventDestroy(start); cudaEventDestroy(stop); cudaDeviceSynchronize(); } int main(int argc, char **argv) { host_vector<int> hv(1); hv[0] = 0xAABBCCDD; device_vector<int> dv(1); dv = hv; int* rp = thrust::raw_pointer_cast(&dv[0]); auto benchFun = [&](void) { child<<<dim3(NBLOCKS,1,1), dim3(NTHREADS,1,1)>>>(rp); }; runBench(benchFun, rp, "Single kernel launch"); auto benchFun2 = [&](void) { for (int j = 0; j < 2; j++) child<<<dim3(NBLOCKS,1,1), dim3(NTHREADS,1,1)>>>(rp); }; runBench(benchFun2, rp, "2x sequential kernel launch"); auto benchFunDP = [&](void) { parent<<<dim3(NBLOCKS,1,1), dim3(NTHREADS,1,1)>>>(rp); }; runBench(benchFunDP, rp, "Nested kernel launch"); } and cast to prepareForSegue if the identifier is equal to your expected segue identifier

Something like this

DashboardViewController
相关问题