1、NSTimer在对@selector(onTimer:)传递参数时,将传参的对象储存在了NSTimer的userInfo的字典里,在- (void)onTimer:(NSTimer *)timer中
通过取出该字典加以使用。
- (void)onTimer:(NSTimer *)timer
{
//通过[timer userInfo] 取出参数
UIView *oldView = [[timer userInfo] objectForKey:@"oldView"];
}
2、直接传参
[self performSelectorOnMainThread:@selector(addNotifications:)withObject:[NSArrayarrayWithObjects:@"1",@"2",nil]waitUntilDone:NO];
该方法参数写在object中,
-(void)addNotifications:(NSArray*)data{
if(data==nil||data.count!=2) {
return;
}
//nsstring字符串转nsinteger
NSInteger notifyNum=[(NSString*)data[0] intValue];
NSInteger index=[data[1] intValue];
MyNBTabButton *button=_buttonData[index];
[button.light addNotifications:notifyNum];
}