【发布时间】:2011-12-23 10:38:01
【问题描述】:
我现在遇到的问题是
我正在调用这个方法: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
来自 vc1
我有一个来自 vc1 的 string1,但不能在该方法中调用它
因为图像委托方法是从不同的类调用的。
当我 NSLog(@"%@", string1);它只显示空
我想从图像委托方法中检索 string1。
有人知道怎么做吗?非常感谢。
来源:
从视图控制器
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSLog(@"%@", requestString);
NSArray *components = [requestString componentsSeparatedByString:@":"];
for (int i=0; i< [components count]; i++) {
NSLog(@"components %@", [components objectAtIndex:i]);
}
if([components count] <= 1) {
return YES;
}
if ([(NSString *)[components objectAtIndex:0] isEqualToString:@"toapp"]) {
NSLog(@"toapp %@", [components objectAtIndex:0]);
// 1번째 문자열이 toApp인 경우
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"showphoto"]) {
NSLog(@"showphoto %@", [components objectAtIndex:1]);
// 2번째 문자열이 relationButton인 경우
NSLog(@" objectAtIndex:2 %@", [components objectAtIndex:2]); // param2
pictureName = [components objectAtIndex:2];
//call photo library
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:YES];
return NO;
}
}
return YES;
}
我声明:
NSString *string1;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
viewcontroller *v = [[viewcontroller alloc]init];
NSLog(@"string1 %@", v.string1);
}
exc_bad_access
从控制台: string1 (null)
我想从控制台查看字符串 Helloworld。 我无法从 imagePickerController 委托方法中调用字符串图片名称。
【问题讨论】:
-
你试过self.string1吗?如果你调试,打开 self 部分,你能看到字符串 Helloworld 吗?
-
我认为这是因为委托方法是从不同的类调用的,因为它说 exec bad access on string1 我需要知道如何从 diff 类调用 string1
-
如何删除我的帖子?我犯了一个错误。