开发者

Function with variable blind to a button xcode

Hi I have a problem i can not send parameter for function

-(IBAction)ukazObrat:(NSInteger *)cis {     
    stvrtyViewController *screen = [[stvrtyViewController alloc] initWithNibName:nil bundle:nil];
    screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:screen animated:YES];
    screen.obratLabel.font = [UIFont systemFontOfSize: 12];
    screen.obratLabel.numberOfLines = 0;
    screen.obratLabel.text = [array objectAtIndex:cis];
    [screen release];   
}

I set this function to a button klick but I m unable to compile it when I add parameter to it.

button = [UIButton buttonWit开发者_如何转开发hType:UIButtonTypeRoundedRect];
[button.titleLabel setLineBreakMode:UILineBreakModeWordWrap];    
[button.titleLabel setTextAlignment:UITextAlignmentLeft];       
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[button setTitle:obratLable forState:UIControlStateNormal];
[button addTarget:self 
           action:@selector([self ukazObrat:minus]
 forControlEvents:UIControlEventTouchDown];             
button.frame = CGRectMake(0.0, 0.0, 250.0, 60.0);

It was working until I add there the variable. please help


[button addTarget:self action:@selector(buttonHandler) forControlEvents:UIControlEventTouchDown];  

Then define buttonHandler as:

- (void)buttonHandler {
  [self ukazObrat:minus];
}

Manage minus however is necessary.


You can't set variable into selector definition. Definition can contain only function name. And number of colons will show compiler how much parameters this function required. Selector for button can have one argument - pointer to event-sender button. If you want to send some data from one controller to another you should create some shared storage for that data.

I use for that purpose singleton class with mutable dictionary inside it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜