좋아, 아직 iOS 개발에 익숙하지 않으므로 바보 같은 질문 인 경우 사과드립니다.AppDelegate에서 UINavigationController에 액세스하려고 시도합니다.
그러나 에서 전화를 걸어서 AppDelegate
에서 경고 단추를 클릭 할 때 응답합니다. 나는 NSLog
을 할 수 있고 메소드가 호출되는 것을 볼 수 있습니다. 그러나 뷰를 스택으로 밀어 넣지는 않습니다. 여기에 내가 무엇을의 샘플입니다 (나는 그것이 잘못 확신) :
이것은 AppDelegate.m
에 있습니다
#import "AppDelegate.h"
#import "ProfileConnection.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
-(void)switchToController:(NSString *)controller animated:(BOOL)animated{
NSLog(@"switching to controller %@", controller);
// maybe we can do a check to see if a subview exists...and then push or pop accordingly.
// switch to the "TableView" view
if([controller isEqualToString:@"ProfileConnection"]){
NSLog(@"switching to the ProfileConnection view");
ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:@"ProfileConnection" bundle:nil];
[self.navController pushViewController:profile animated:YES];
}
}
-(void)showConnectionFoundAlert
{
NSString *connectFoundMsg = [[NSString alloc] initWithFormat:@"We found someone we'd think you would like to meet: Tony Davis"];
UIAlertView *connectionFoundAlert = [[UIAlertView alloc] initWithTitle:@"Connection Found" message:connectFoundMsg delegate:self cancelButtonTitle:@"Decline" otherButtonTitles:@"Connect", @"View Profile", @"Save For Later", nil];
[connectionFoundAlert show];
//[connectionFoundAlert release];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
NSString *alertString = [[NSString alloc] initWithFormat:@""];
if([title isEqualToString:@"Decline"])
{
alertString = @"Declied";
}
else if([title isEqualToString:@"Connect"])
{
alertString = @"Connected";
}
else if([title isEqualToString:@"View Profile"])
{
//alertString = @"Profile Viewed";
//NSLog(@"View Profile is being called");
[self switchToController:@"ProfileConnection" animated:YES];
//UIViewController *profile = [[UIViewController alloc] initWithNibName:@"ProfileConnection" bundle:nil];
//ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:@"ProfileConnection" bundle:[NSBundle mainBundle]];
//UINavigationController *nav = [[UINavigationController alloc] init];
//[nav pushViewController:profile animated:NO];
/*UIViewController *profile = [[UIViewController alloc] initWithNibName:@"ProfileConnection" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc] init];
[navigation pushViewController:profile animated:YES];*/
/*
ProfileConnection *profile = [ProfileConnection alloc];
//UIView *current = self.window;
[self.window addSubview:profile.view];
*/
/*
[window addSubview:view1.view];
[window makeKeyAndVisible];
- (void)goToNextPage {
view2 = [ViewController2 alloc];
UIView *current = self.window;
[self.window addSubview:view2.view];
*/
}
else if ([title isEqualToString:@"Save For Later"])
{
alertString = @"Saved It";
}
UIAlertView *alertStr = [[UIAlertView alloc] initWithTitle:@"" message:alertString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
if ([alertString isEqualToString:@""]) {
} else {
[alertStr show];
}
}
@end
이것은 AppDelegate.h
입니다 : 내가 추가 할 수 있어요
#import <UIKit/UIKit.h>
#import "ProfileConnection.h"
@interface AppDelegate : UIResponder <UIAlertViewDelegate, UIApplicationDelegate, UINavigationControllerDelegate> {
UINavigationController *navController;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) UINavigationController *navController;
-(void)showConnectionFoundAlert;
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
-(void)switchToController:(NSString *)controller animated:(BOOL)animated;
@end
이것으로보기,하지만 내 탐색 컨트롤러를 잃게 :
ProfileConnection *profile = [ProfileConnection alloc];
[self.window addSubview:profile.view];
내가 볼 수있는 tr 몇 가지 접근 방식을 사용했지만 스토리 보드 방식을 사용하려고 혼란 스럽습니다.
또한 ProfileConnection보기는 비어 있으며 현재 도움이되는 경우 단일 레이블이 비어 있습니다.
navController를 어떻게 만듭니 까? – ader
ProfileConnection 코드도 함께 표시하십시오. – ader
세 번째 코드 발췌 문장의 출처는 어디입니까? App Delegate에서'pushViewController'는 스택에 무언가를 얻는 방법입니다. – Walter