【发布时间】:2011-05-26 01:50:34
【问题描述】:
我一直在为 iPad 开发校报应用程序。我终于能够解析我需要的文章。我用 UITextView 将每篇文章的摘要放在父视图控制器上。现在我要做的是在按下 UITextView 顶部的自定义按钮时使用 ModalViewController 显示每篇文章。我在 StackOverFlow 中查看了几个 QA,但无法使我的项目正常工作。我将把我的一些代码和一些日志放在控制台上。任何帮助将不胜感激。提前致谢。
在我的 ArticleViewController.h 中(与 ModalViewController.h 相同)
@interface ArticleViewController : UIViewController {
IBOutlet UIButton *doneReadingButton;
IBOutlet UITextView *articleTextView;
}
@property (nonatomic, retain) UIButton *doneReadingButton;
@property (nonatomic, retain) UITextView *articleTextView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withText:(NSString *)text;
-(IBAction)doneReadingArticle:(id)sender;
//-(IBAction)displayArticleView:(id)sender;
@end
在我的 ArticleViewController.m 中(与 ModalViewController.m 相同)
#import "ArticleViewController.h"
@implementation ArticleViewController
@synthesize doneReadingButton;
@synthesize articleTextView;
- (IBAction)doneReadingArticle:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
//This is where I need to display main article in modal view
/*
- (IBAction)displayArticleView:(id)sender {
[self presentModalViewController:articleTextView animated:YES];
}
*/
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withText:(NSString *)text {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
//self.articleTextView = [[UITextView alloc] init];
//self.articleTextView.text = [text retain];
self.articleTextView.text = text;
}
NSLog(@"********text in modal init******** >> %@",articleTextView.text);
return self;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
//I guess, this is where I have to load main article
self.articleTextView.text = @"This is a test!";
NSLog(@"********text in modal******** >> %@",articleTextView.text);
}
在我的父视图控制器中
-(IBAction)articleView04:(id)sender{
storyView04 = [[ArticleViewController alloc] initWithNibName:@"ArticleViewController" bundle:[NSBundle mainBundle]];
storyView04.articleTextView.text =[NSString stringWithString:@"TESTING! TESTING!"];
[storyView04 setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
storyView04.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:storyView04 animated:YES];
[storyView04 release];
}
所以,在控制台中,我得到了这个,它只是一个占位符文本。
2011-05-28 15:44:00.071 TheCalAggie[4179:207] ********text in modal******** >> This is a test!
我知道我必须将文本值从父视图传递给 ModalViewController,但我不确定我是否正确传递它。我的代码一开始有意义吗?
无论如何。请帮我完成这个项目。我真的必须在一周内完成它。再次感谢。
【问题讨论】:
标签: objective-c xcode ipad modalviewcontroller