2012-08-26 143 views
0

這是我嘗試在IOS中建立我的第一個應用程序,我有一些問題。雖然我在這裏看過類似的線索,但我無法找到答案。財產未找到類型的對象

那麼這裏有我的課:

Homeview.h

@interface HomeView : UIViewController{ 

    NSString *parsed_date; 
} 

@property (nonatomic,retain) NSString *parsed_date; 

@end 

Homeview.m

@synthesize parsed_date; 
parsed_date=[res objectForKey:@"date"]; 

,我想通常打印出在我homeview其他傳遞日期視圖。

這裏是我的其他類:

Otherclass.h

#import <UIKit/UIKit.h> 

@interface OtherView : UIViewController{ 
    NSString* tracks_date; 
} 
@property (nonatomic,retain) NSString* tracks_date; 
@end 

Otherclass.m

#import "OtherView.h" 
#import "HomeView.h" 

@interface OtherView() 

@end 

@implementation OtherView 
@synthesize tracks_date; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    //preview value of other class 
    NSLog(@"Dated previed in OtherView: %@", HomeView.parsed_date); //HERE IS THE ERROR 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

這裏是我的錯誤:

property parsed_date not found on object of type "HomeView" 

回答

3

的問題是你沒有使用HomeView的一個實例。您需要實例化HomeView,然後您可以通過新實例訪問該屬性。

它看起來有點像這樣:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Do any additional setup after loading the view. 
    HomeView *homeView = [[HomeView alloc] init]; 
    homeView.parsed_date = ...assign a value to the property 

    //preview value of other class 
    NSLog(@"Dated previed in OtherView: %@", homeView.parsed_date); //read the value 
} 
+0

我必須釋放它嗎? – ghostrider

+0

好吧,現在我可以在homeView中看到它的值,但在我的otherView中看不到它的值。 – ghostrider

+0

是否需要釋放它取決於您是否啓用了(ARC)自動引用計數。對於iOS,我認爲它在iOS4及更高版本中默認啓用。如果啓用ARC,則不需要手動釋放它。 http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html – user1610694

0

如果你真的很肯定的是,你已經正確聲明的一切,但是你不斷收到「找不到屬性」,然後:

確保你所有的文件都在同一個文件夾中。

,因爲這是發生在我身上。我有兩個項目文件夾,其中一個用於測試。我不小心將一些文件從測試文件夾拖到了我的主要xcode項目中。它只在使用舊屬性時編譯好,但始終得到「屬性未找到」錯誤,因爲測試文件夾中的文件無法看到我添加到主項目的新屬性。

希望這可以幫助未來的人。

相關問題