1
晚上好,我試圖創建一個按鈕的網格,就像在下面的代碼中一樣。 我想爲每個按鈕添加TapGesture和LongPress手勢;我該怎麼做? 我知道這是一個辦法做到這一點......當創建按鈕的網格時點擊和長按手勢Objective-C
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
longPress.minimumPressDuration = 3;
//[self.griglia[1][1] addGestureRecognizer:longPress];
如果我這樣做,它說:「財產‘griglia’不是類型的對象Gioco發現 Gioco.m/Gioco.h是我的課
和的UIButton * griglia [9] [9];是我的按鈕電網
你能糾正下面的代碼
for(int i=0, y=212, p=0; i<9; i++)
{
for(int k=0, x=37; k<9; k++)
{
griglia[i][k] = [UIButton buttonWithType:(UIButtonTypeCustom)];
//[griglia[i][k] addTarget:self action:(@selector(click)) forControlEvents: UIControlEventTouchDown];
[griglia[i][k] setTag: 0];
if(i==posizioni[0][p] && k==posizioni[1][p])
{
numero=[NSString stringWithFormat:@"%d", matrice[i] [k]];
[griglia[i][k] setTitle: numero forState: UIControlStateNormal];
[griglia[i][k] setEnabled:NO]; //Numeri non modificabili
[griglia[i][k] setTag: matrice[i][k]];
}
[griglia[i][k] setTitleColor:[UIColor blackColor] forState: UIControlStateNormal];
griglia[i][k].frame=CGRectMake(x, y, 27, 27);
[self.view addSubview:griglia[i][k]];
if(k==2 || k==5)
x=37+3+k*34;
else
x=37+k*34;
}
if(y==2 || y==5)
y=212+4+i*34;
else
y=212+i*34;
}