我學習可可...... 我嘗試了不同的方式來做到這一點,但我仍然在黑...方法調用 - 可可/對象 -
我有我的執行這個方法:
- (void)closeStream:(NSStream *)theStream {
[theStream close];
[theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
如何從我的@synthetize中的IBAction中調用它?
- (IBAction)connect:(id)sender {
if ([[connectNOK stringValue] isEqualToString:@"Disconnected"]) {
[connectButton setTitle:@"Disconnect"];
NSString * hostFromField = [hostField stringValue];
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)hostFromField, [portField intValue], &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
} else {
[connectButton setTitle:@"Connect"];
// I want to call this method here
}
}
這是完整的語言規範。對於新人來說,最好從[學習目標-C:入門]開始(http://developer.apple.com/library/mac/referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/)。 –
你完全正確,謝謝:)更正了我的答案和你的鏈接。 – Macmade
我解決了這個問題,謝謝你的回答。 –