Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Objective-C中如何将布尔值从一种方法发送到另一种方法_Ios_Objective C - Fatal编程技术网

Ios 在Objective-C中如何将布尔值从一种方法发送到另一种方法

Ios 在Objective-C中如何将布尔值从一种方法发送到另一种方法,ios,objective-c,Ios,Objective C,这是接听来电的代码,原始代码只是 自动接听电话 我正在更改它,以便在检测到传入呼叫时,能够得到应答 按钮出现,该按钮可用(与[\u answerButton setAlpha:1];),但 然后我想通过单击该按钮来接受连接。我试过了 只是移动: [connection accept]; _connection = connection; 对于answerCall方法,但由于某种原因,它不起作用。所以现在 我只想添加一些代码,当我单击时,将BOOL设置为true 按下应答按钮,将

这是接听来电的代码,原始代码只是 自动接听电话

我正在更改它,以便在检测到传入呼叫时,能够得到应答 按钮出现,该按钮可用(与
[\u answerButton setAlpha:1];
),但 然后我想通过单击该按钮来接受连接。我试过了 只是移动:

    [connection accept];
    _connection = connection;
对于answerCall方法,但由于某种原因,它不起作用。所以现在 我只想添加一些代码,当我单击时,将BOOL设置为true 按下应答按钮,将该BOOL传回
didAnswerCall
,然后添加一个 否则,如果该方法为true,则该方法将接受连接

- (IBAction)answerCall:(id)sender {
    // Need code to run didReceiveIncomingConnection method again, 
    // but pass Bool for didAnswerCall that equals true
}

- (void)device:(TCDevice *)device
didReceiveIncomingConnection:(TCConnection *)connection
{
    NSLog(@"Incoming connection from: %@", [connection parameters][@"From"]);
    if (device.state == TCDeviceStateBusy) {
        [connection reject];
    }
    // Need else if code in here that says if didAnswerCall is true,
then [connection accept]
    else {
        [_answerButton setAlpha:1];

        //[connection accept];
        //_connection = connection;
    }
}
“我尝试将[connection accept];_connection=connection;移动到answerCall方法,但由于某些原因,该方法无效。”-如果这导致您的
-answerCall:
方法如下所示:

- (IBAction)answerCall:(id)sender {
    [connection accept]; 
    _connection = connection;
}
那么它不起作用是可以理解的。在上述代码中,
连接
未在
-answerCall
方法的范围内声明。对其调用方法没有任何意义。事实上,这不应该编译

我不认为在你们班上传递布尔值是最好的选择。通过尝试接受
-answerCall
中的连接,您已经成功了。您所需要的只是让您的类持有对
连接的引用。在
@界面中
尝试添加属性,以便类的实例能够记住
连接

@interface YourClass()

@property (nonatomic) TCConnection *connection;

// other code ...

@end

@implementation YourClass

- (IBAction)answerCall:(id)sender {
    if (self.connection) {
        [self.connection accept];
    }
}

- (void)device:(TCDevice *)device
didReceiveIncomingConnection:(TCConnection *)connection {
    NSLog(@"Incoming connection from: %@", [connection parameters][@"From"]);
    if (device.state == TCDeviceStateBusy) {
        [connection reject];
    }
    else {
        // remember the connection here
        self.connection = connection;
        [_answerButton setAlpha:1];
    }
}

// other code ...

@end

非常感谢你,菲利普!!这是我在stackoverflow上的第一个问题,你的解决方案非常有效!!