0
嗨,我有两个viewControllers。在两个ViewControllers之间传递数据问题
NewsViewController
#import "SingleViewController.h"
@interface NewsViewController : UIViewController {
}
- (NSString *)getFirstImage:(NSString *)htmlString;
@end
和实现文件:
#import "SingleViewController.h"
SingleViewController *singleViewController;
@interface NewsPadViewController() <UIActionSheetDelegate>
- (void)loadSubscriptions;
@property (nonatomic, assign) BOOL wrap;
@property (nonatomic, retain) NSMutableArray *items;
@end
@implementation NewsPadViewController
....CODE....
- (void)carouselCurrentItemTapped{
//[self addSubview:articolo];
MWFeedItem *item =[reader.feedItems objectAtIndex:[carousel currentItemIndex]];
NSLog(@"Current Item tappped, index: %d", [carousel currentItemIndex]);
[email protected]"CIAO";
[email protected]"sample";
[singleViewController.web loadHTMLString:item.summary baseURL:nil];
NSLog(@"conternutio:");
NSLog(singleViewController.ciao);
}
SingleViewController.h
#import <UIKit/UIKit.h>
@interface SingleViewController : UIViewController{
@public
UIWebView *web;
UILabel *prova;
NSString *ciao;
}
@property (nonatomic,retain) IBOutlet UIWebView *web;
@property (nonatomic,retain) IBOutlet UILabel *prova;
@property (nonatomic,retain) IBOutlet NSString *ciao;
@end
和SingleViewController.m
#import "SingleViewController.h"
@implementation SingleViewController
@synthesize web,prova,ciao;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[prova setText:ciao];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
为什么我无法从SingleViewController中的对象访问NewsPadViewController?我的错误在哪里?感谢 UPADATE
- (void)carouselCurrentItemTapped{
//[self addSubview:articolo];
MWFeedItem *item =[reader.feedItems objectAtIndex:[carousel currentItemIndex]];
NSLog(@"Current Item tappped, index: %d", [carousel currentItemIndex]);
SingleViewController *singleViewController = [[SingleViewController alloc] initWithNibName:@"SingleViewController" bundle:[NSBundle mainBundle]];
[email protected]"CIAO";
[email protected]"sample";
[singleViewController.web loadHTMLString:item.summary baseURL:nil];
NSLog(@"conternutio:");
NSLog(singleViewController.ciao);
[singleViewController setOpz:@"sample"];
}
谢谢我添加了第一部分的代码和NSLog(singleViewController.ciao)的作品!但在xib中不起作用! ciao NSString没有加载到UILabel中,UIWebView没有任何东西! – 2011-06-16 17:24:40
听起来像你没有在界面生成器中设置你的网点 – Kwexi 2011-06-16 17:35:30
插座是正确的!我尝试从viewDidLoad方法中分配UILabel中的文本,它的工作原理!问题只在于我在newsPadViewController中分配的那个刺痛!事实上,如果我从SingleViewController中的viewDidLoad尝试NSLog(ciao),字符串为空,而如果我从NewsPadViewController尝试NSLog(SingleViewController.ciao),它包含文本“sample” – 2011-06-16 18:45:58