ios - 单击按钮更改标签上的文本

标签 ios ios-4.2 ios4

我想知道如何通过单击按钮来更改标签上的文本,我有 2 个按钮,分别名为添加和减号,如果我们单击添加按钮,每次单击时,它会从 1 增加到 10,如果我们单击在减号按钮上,它应该从 1-10 减少,

我尝试做一些事情,如下所示

-(IBAction) addQuantity
{
    for (int i=1;i<11; i++)
    {
        [m_label setText:[NSString stringWithFormat:@"%i",i]];
    }

}

请 friend 们告诉我如何进行,

问候 兰 git

最佳答案

NSInteger counter = 0;
-(IBAction) addQuantity
{
    if (counter > 9 )
        return;
    [m_label setText:[NSString stringWithFormat:@"%d",++counter]];
}

-(IBAction) minusQuantity
{
    if (counter < 1 )
        return;
    [m_label setText:[NSString stringWithFormat:@"%d",--counter]];
}

关于ios - 单击按钮更改标签上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7752493/

相关文章:

iphone - 我们可以在 iOS 设备上使用 Mapkit 框架在 Google map 上显示 KML 数据吗?

iphone - 如何在 iOS 4.2 中将视频放入 iPhone 模拟器相机胶卷中?

objective-c - 以编程方式绘制粗略的线条

iphone - iOS UINavigationBar 标题文本颜色 (iOS 4)

iphone - 使 iPhone 应用程序与 iOS 3 兼容

objective-c - 底栏工具栏按钮的问题

ios - tableView.setContentOffset 不适用于嵌入在 UIViewcontroller 中的 UITableView

ios - Swift UIView 从堆栈 View 中消失

ios - NSURLCache 和 ETag

配置 : error: C compiler cannot create executables in mac os terminal