1

我在此代码上的 performSelector 方法遇到了一些问题:

此方法在其他名为“JSONMethods”的类中:

+(void)sendPostMsgWithMultipleArguments:(NSArray *)myArgs {
[self sendPostMsg:[myArgs objectAtIndex:0]:[myArgs objectAtIndex:1]];
}

然后,在另一堂课上,我接到了电话:

- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Loading...";

JSONMethods *methods = [[JSONMethods alloc]init];
NSArray *arguments = [[NSMutableArray alloc]initWithObjects:@"http://localhost/promos/txFirmas.php",[NSString stringWithFormat:@"sensor=%d",tableViewNumber], nil];
[methods performSelector:@selector(sendPostMsgWithMultipleArguments:)
           withObject:arguments
           afterDelay:3.0];

NSString *tit = [NSString stringWithFormat:@"Sign: %d",tableViewNumber];
self.title = tit;
}

我想等到“sendPostMsgWithMultipleArguments:”完成更改标题,我该怎么做?当我对此进行测试时,mi app 崩溃并通过控制台向我显示:

2012-08-17 12:09:15.966 MapaProject[524:11603] -[JSONMethods sendPostMsgWithMultipleArguments:]: unrecognized selector sent to instance 0x7c85b70
2012-08-17 12:09:15.968 MapaProject[524:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[JSONMethods sendPostMsgWithMultipleArguments:]: unrecognized selector sent to instance 0x7c85b70'
*** First throw call stack:
(0x133a022 0x2016cd6 0x133bcbd 0x12a0ed0 0x12a0cb2 0xa1c85d 0x130e936 0x130e3d7 0x1271790 0x1270d84 0x1270c9b 0x15db7d8 0x15db88a 0xf6626 0x236d 0x20c5)
terminate called throwing an exception

你能帮助我吗?提前致谢 :)

4

3 回答 3

1

改变+(void)sendPostMsgWithMultipleArguments:(NSArray *)myArgs

-(void)sendPostMsgWithMultipleArguments:(NSArray *)myArgs

甚至更好的改变

[methods performSelector:@selector(sendPostMsgWithMultipleArguments:) withObject:arguments afterDelay:3.0];

[[methods class] performSelector:@selector(sendPostMsgWithMultipleArguments:) withObject:arguments afterDelay:3.0];

于 2012-08-17T10:37:19.413 回答
0

NSArray * mutArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:0],[NSNumber numberWithInt:2], nil]

[self performSelector:@selector(loadMore:) withObject:mutArray afterDelay:1.9];

-(void)loadMore:(NSArray *)array
{
 NSNumber * myNumber = [array objectAtIndex:0];
 NSNumber * myNumber2 = [array objectAtIndex:1];

}

于 2014-06-04T14:04:12.897 回答
0

在迅速 3

您可以制作字典来保存多个参数并与选择器一起传递

let argumentsDict = ["arg1Key": arg1Value, "arg2Key": arg2Value] as [String : Any]

perform(#selector(selectorWithMultipleArg), with: argumentsDict, afterDelay: 3.0)

在选择器函数内部,使用guard取出值并使用它们。我使用 2 个不同类型的参数来更好地解释 .ie Int 和 String

func selectorWithMultipleArg(_ arguments: [String: Any]) {

    guard let arg1Value = arguments["arg1Key"] as? Int else {
        fatalError("Invalid value 1")
    }

    guard let arg2Value = arguments["arg2Key"] as? String else {
        fatalError("Invalid value 2")
    }
    print("Value 1: \(arg1Value)")
    print("Value 2: \(arg2Value)")

}

我希望这会对你有所帮助

于 2017-05-12T05:51:27.060 回答