문제는 내가받은 컨트롤러 데이터를 밀어 넣거나 모달보기로 제시 한 후에 어떻게 저장할 수 있는지 잘 모르는 것입니다. 스토리 보드, ARC, iOS5를 사용하고 있습니다. 프로젝트가 xib를 사용할 때 모든 것이 잘 작동했습니다. 대상 ViewController UIWebView 있고 트위터 OAuth 인증을 위해 전송 된 URL을 열 필요가. 다음은 WebViewController의 함수를 호출하는 TweetViewController 코드입니다. 그런 다음 UIWebController가있는 UIViewController를 표시하려고합니다. 그러나 URL을 전송 한 후에는이 데이터를 잊어 버립니다. 따라서 ViewDidLoad 함수에서 NSURL은 null입니다. URL 데이터 전송 TweetViewController.m의대상 컨트롤러에서 데이터 손실없이 모달 뷰를 열려면 어떻게해야합니까?
// TweetViewController.h
#import <UIKit/UIKit.h>
#import "RSTwitterEngine.h"
#import "WebViewController.h"
@interface TweetViewController : UIViewController <RSTwitterEngineDelegate, WebViewControllerDelegate>
@property (strong, nonatomic) RSTwitterEngine *twitterEngine;
@property (strong, nonatomic) WebViewController *leWebView;
@property (unsafe_unretained, nonatomic) IBOutlet UITextView *textView;
@property (unsafe_unretained, nonatomic) IBOutlet UIBarButtonItem *sendButton;
@property (unsafe_unretained, nonatomic) IBOutlet UILabel *statusLabel;
- (IBAction)sendTweet:(id)sender;
- (void)swipedRight:(UIGestureRecognizer *)recognizer;
@end
부 :에서 WebViewController.m
#import "WebViewController.h"
#import "AppDelegate.h"
@implementation WebViewController
@synthesize delegate = _delegate;
@synthesize currentURL = _currentURL;
@synthesize leWebView = _leWebView;
@synthesize leActivityIndicator = _leActivityIndicator;
#pragma mark - Initialization
// ======= Here is that function which recieves url ========
- (id)initWithURL:(NSURL *)url
{
self = [self.storyboard instantiateViewControllerWithIdentifier:@"WebView"];
NSLog(@"WebViewController initWithURL called. Recieved url = %@", url);
if (self) {
self.currentURL = url;
self.delegate = nil;
}
return self;
}
#pragma mark - View Lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"WebViewController viewDidLoad called. currentURL = %@", self.currentURL);
self.leWebView.scalesPageToFit = YES;
[self.leWebView loadRequest:[NSURLRequest requestWithURL:self.currentURL]];
}
- (void)viewDidUnload
{
[self setLeWebView:nil];
[self setLeActivityIndicator:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - UIWebView Delegate Methods
- (BOOL)LeWebView:(UIWebView *)LeWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.scheme isEqualToString:@"rstwitterengine"] && (self.delegate)) {
if (self.leActivityIndicator) [self.leActivityIndicator stopAnimating];
[self.delegate handleURL:request.URL];
return NO;
} else {
return YES;
}
}
- (void)webViewDidStartLoad:(UIWebView *)LeWebView
{
if (self.leActivityIndicator) [self.leActivityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)LeWebView
{
if (self.leActivityIndicator) [self.leActivityIndicator stopAnimating];
}
- (void)LeWebView:(UIWebView *)LeWebView didFailLoadWithError:(NSError *)error
{
if (self.leActivityIndicator) [self.leActivityIndicator stopAnimating];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}
#pragma mark - Custom Methods
- (IBAction)ActionNoMore:(id)sender {
if (self.delegate) [self.delegate dismissWebView];
}
@end
// WebViewController.h
#import <UIKit/UIKit.h>
@protocol WebViewControllerDelegate;
@interface WebViewController : UIViewController <UIWebViewDelegate>
@property (retain, nonatomic) NSURL *currentURL;
@property (assign, nonatomic) id <WebViewControllerDelegate> delegate;
@property (retain, nonatomic) IBOutlet UIWebView *leWebView;
@property (retain, nonatomic) IBOutlet UIActivityIndicatorView *leActivityIndicator;
- (id)initWithURL:(NSURL *)url;
- (IBAction)ActionNoMore:(id)sender;
@end
@protocol WebViewControllerDelegate <NSObject>
- (void)dismissWebView;
- (void)handleURL:(NSURL *)url;
@end
과 : 그래서 여기
#pragma mark - RSTwitterEngine Delegate Methods
- (void)twitterEngine:(RSTwitterEngine *)engine needsToOpenURL:(NSURL *)url
{
self.leWebView = [_leWebView initWithURL:url];
self.leWebView.delegate = self;
[self performSegueWithIdentifier:@"LeWebSegue" sender:self];
//[self presentModalViewController:self.leWebView animated:YES];
}
는 WebViewController 핵심 부품이다 모두,로드하려고 할 때 그보기, 나는 WebViewController viewDidLoad라는 로그 메시지를받습니다. currentURL = (null)
당신을 발견해 주셔서 감사합니다. 하지만 안전을 기하기 위해 initWithURL 메소드를 통해 메모리 누수가 있는지 확인할 수도 있습니다. 나는 확신 할 수 없지만 당신은 스토리 보드 instantiateViewControllerWithIdentifier을 실행할 때 당신이 누출 될 수있다. 행운을 빕니다! – Rob