ios - 如何从 UIButton 调用的操作发送方法以查看
<p><p>我理解(我认为)为什么这不起作用,但我不知道如何让它起作用。</p>
<p>我有一个像这样在 <code>viewWillAppear</code> 中调用的方法(为了这个问题,我已经简化了代码):</p>
<pre><code>- (void)viewWillAppear:(BOOL)animated
{
;
}
</code></pre>
<p>然后我有一个小的 for 循环在 <code>viewDidLoad</code> 中构建一些按钮:</p>
<pre><code>NSUInteger b = 0;
for (UIButton *hourButton in hourButtons) {
;
forState:UIControlStateNormal];
;
b++;
}
</code></pre>
<p>那么对于我的操作:</p>
<pre><code>- (IBAction)showHour:(id)sender
{
// Logs 0, 1, etc. depending on which button is tapped
NSLog(@"Button tag is: %lu", (long int));
// This currently throws this error:
// No visible @interface for 'UIView' declares the selector 'displayHour:'
// What I want to do is be able to call this method on
// the main view and pass along the button tag of the
// button that was tapped.
];
}
</code></pre>
<p><strong>问题</strong>是如何从 <code>showHour:</code>Action 调用 <code>displayHour</code> 到主视图? </p>
<p>如果需要,displayHour方法长这样(简化了,基本更新了主视图上的一些标签和图片 View ):</p>
<pre><code>- (void)displayHour:(NSUInteger)i
{
// The temperature
hourTemp = [ valueForKeyPath:@"temperature"];
// The icon
hourIcon = [ valueForKeyPath:@"icon"];
// The precipitation
hourPrecip = [ valueForKeyPath:@"precipProbability"];
// SET DISPLAY
;
;
;
}
</code></pre>
<p>谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>代替</p>
<pre><code> ];
</code></pre>
<p>做:</p>
<pre><code> ];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何从 UIButton 调用的操作发送方法以查看,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19203281/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19203281/
</a>
</p>
页:
[1]