I followed a book to make a application based app with code as below, then I tried use textView in NIB file, but I could"t show text, what can I do?
Code:
// SourceReaderAppDelegate.h
#import <UIKit/UIKit.h>
@class SourceReaderViewController;
@interface SourceReaderAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
SourceReaderViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet SourceReaderViewController *viewController;
@end
Code:
// SourceReaderAppDelegate.m
#import "SourceReaderAppDelegate.h"
#import "SourceReaderViewController.h"
@implementation SourceReaderAppDelegate
@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
Code:
// SourceReaderViewController.h
#import <UIKit/UIKit.h>
@interface SourceReaderViewController : UIViewController {
UITextView *textView;
}
@end
Code:
// SourceReaderViewController.m
#import "SourceReaderViewController.h"
@implementation SourceReaderViewController
@synthesize textView;
using a nib.
- (void)loadView {
CGRect bounds = [[UIScreen mainScreen] applicationFrame];
[super loadView];
textView = [[UITextView alloc] initWithFrame:bounds];
UIColor *myBlue = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];
textView.textColor = myBlue;
UIFont *myFixed = [UIFont fontWithName:@"Courier New" size:24.0];
textView.font = myFixed;
textView.editable = NO;
NSURL *url = [NSURL URLWithString:@"http://yahoo.co.jp"];
NSString *pageData = [NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding error:nil];
textView.text = pageData;
self.view = textView;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[textView dealloc];
[super dealloc];
}
@end