从另一个方法调用 IBAction



我是Objective-C,Xcode和所有好东西的新手。我是自学成才的。

我正在尝试从另一种方法调用IBAction

- (IBAction)strAdj:(UIStepper *)strStepper
{
// Converts stepper to integer
NSUInteger strvalue = strStepper.value;
// Changes the the text to the value of the stepper
strStat.text = [NSString stringWithFormat:@"%2d", (unsigned)strvalue];
_strMod.text = [NSString stringWithFormat:@"%2d", (unsigned)stepperAdj(strvalue)];
// Based on the value it change the strMod to a specific value
}

我只发布下一个代码的一部分。这是一个简单switch的说法。我基本上想在下面的虚空中调用上面的IBAction。

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (row) {
case 0:
break;
// Core races never change
// defines dwarf stats
case 1:
// sets all the increases
tempCon = 2;
tempWis = 2;
tempChr = -2;
// resets all other stats
tempStr = 0;
tempDex = 0;
tempInt = 0;
// I want to call the IBAction here... 
break;

这种IBAction最终需要发生 15 次。更改选取器时,会出现上述switch语句。每次步进发生时都会发生IBAction

我希望我离我想做的事情不会太远。同样,我只是在过去的几天里一直在使用它,我无法找到我正在寻找的东西,或者如果我找到了,那么我不确定该怎么做。

看起来你有一个下拉菜单供玩家选择一个种族,每个属性(str、con、wis 等)都有一个步进器来向上或向下提升相应的值。

我不知道足够的推测,但我怀疑总体上有一个更好的方法。 也就是说,我认为您要做的一个蛮力解决方案是确保您的每个步进器都有一个参考出口:stepperWis,stepperCon,stepperInt等。 然后在您的开关中,您可以执行以下操作(针对每个属性):

stepperWis.value = (whatever value you want);
[self strAdj:self.stepperWis];

你可以像这样编程调用UIButton TouchUpInside事件:

[YourButtonObject sendActionsForControlEvents: UIControlEventTouchUpInside];

最新更新