我是Objective-C和iPhone SDK開發的新手。我想調用一個方法,在同一個班級:目標-C方法調用
- (void) setFilePath:(NSString *) p
{
[self methodCall];
}
- (void) methodCall
{
fileContent.text = @"Test"; //fileContent is a UITextView
}
如果屬性「文件路徑」設置,方法「setFilePath」之稱。然後在IB中創建的UITextView應顯示文本。但是,這並不工作...
如果我在IB直接通過按鈕來調用方法,那麼UITextView的成功改變了他的內容:
- (IBAction) clickButton
{
fileContent.text = @"Test";
}
可能是什麼問題呢?
感謝您的回答!
編輯2:我解決了推視圖後設置 「文件路徑」 的問題:
- (IBAction) showFileContent {
FileContentsViewController *fileContentsViewController = [[FileContentsViewController alloc] init];
[self.navigationController pushViewController:fileContentsViewController animated:YES];
fileContentsViewController.filePath = self.filePath;
fileContentsViewController.title = [NSString stringWithFormat:@"Content from von %@", [filePath lastPathComponent]];
[fileContentsViewController release];
}
編輯1:這是我的界面代碼:
@interface FileContentsViewController : UIViewController {
NSString *filePath;
UITextView *fileContent;
}
- (void) methodCall;
@property (nonatomic, retain) NSString *filePath;
@property (nonatomic, retain) IBOutlet UITextView *fileContent;
@end
。 ..這是實現的代碼:
#import "FileContentsViewController.h"
@implementation FileContentsViewController
@synthesize filePath;
@synthesize fileContent;
- (void) setFilePath:(NSString *) p
{
NSLog(@"setFilePath executed!");
[self methodCall];
}
- (void) methodCall
{
fileContent.text = @"Test"; // UITextView
}
// some standard methods
@end
...最後,設置「文件路徑」的方法的代碼:
- (IBAction) showFileContent {
FileContentsViewController *fileContentsViewController = [[FileContentsViewController alloc] init];
fileContentsViewController.filePath = self.filePath;
fileContentsViewController.title = [NSString stringWithFormat:@"Content from von %@", [filePath lastPathComponent]];
[self.navigationController pushViewController:fileContentsViewController animated:YES];
[fileContentsViewController release];
}
顯示如何調用setFilePath: – JeremyP 2010-11-09 09:05:58
[XCode Debugger](http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/XcodeDebugging/000-Introduction/Introduction.html%23/)/apple_ref/doc/uid/TP40007057-CH1-SW1)也應該能夠告訴你代碼在做什麼。 – outis 2010-11-09 09:32:14
@JeremyP我在設置屬性「filePath」時調用它。該屬性如下所示:@property(nonatomic,retain)IBOutlet UITextView * fileContent。 – 2010-11-09 09:48:15