0
我正在動態創建多個按鈕,現在我想爲每個按鈕設置操作。 當我按下它的顯示結果在我的應用程序的下一個屏幕上。 我正在使用FMDB庫從數據庫中讀取數據(按照按鈕上的id讀取數據庫)。我知道如何從數據庫讀取數據庫。我只想獲取按鈕上的數據,並在桌面視圖上顯示該數據。如何爲每個按鈕創建操作? 這是我的按鈕代碼:如何在ios中創建動作多個動態按鈕?
-(void)DynamicButton:(NSMutableArray*)objectName
{
for(UIView *view in [scrollView subviews])
{
[view removeFromSuperview];
}
int yPossion = 100, xPossion = 44; int temp = 0;
for (int i = 0; i<[objectName count]; i++)
{
SMSCategory *cat = [objectName objectAtIndex:i];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setTag:i];
[aButton setTranslatesAutoresizingMaskIntoConstraints:YES];
[aButton setBackgroundColor:[UIColor blackColor]];
[aButton setBackgroundImage:[UIImage imageNamed:@"icon-menu.png"]
forState:UIControlStateNormal];
[aButton setTitle:[NSString stringWithFormat:@"%d",i]
forState:UIControlStateNormal];
[aButton setFrame:CGRectMake(xPossion, yPossion, 70, 60)];
aButton.highlighted=YES;
[scrollView addSubview:aButton];
;
xPossion += aButton.frame.size.width+35;
temp++;
if (temp==3)
{
yPossion = aButton.frame.origin.y+aButton.frame.size.height+20;
temp = 0;
xPossion = 44;
yPossion += aButton.frame.size.width-15;
[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width ,yPossion-
50)];
}
UILabel *label = [[UILabel alloc] init];
[label setTranslatesAutoresizingMaskIntoConstraints:YES];
[label setText:cat.Name];
[label setTextColor:[UIColor blackColor]];
label.font = [UIFont systemFontOfSize:12];
[label sizeToFit];
[label setFrame:CGRectMake(4, 44, 70, 60)];
[scrollView addSubview:label];
[aButton addSubview:label];
}
}
這多個按鈕,但如何從明年screeen它的移動當我按下按鈕 – 2014-10-20 15:25:31
使用'@selector(testDoit)'。 。添加移動屏幕代碼init – 2014-10-20 15:28:43
'[button addTarget:self action:inSelector forControlEvents:UIControlEventTouchUpInside];' – 2014-10-20 15:29:28