我是 obj-c 的新手(这是我的第一天课,嗯),我正在尝试使用多维数组中的随机字符串更改标签。另外,每次按下按钮时,您都会切换阵列。我知道这有点奇怪,嗯……这是 IBAction:
UIButton *button = (UIButton *)sender;
NSMutableArray *firstArray = [NSMutableArray array];
[firstArray addObject:@"foo"];
NSMutableArray *secondArray = [NSMutableArray array];
[secondArray addObject:@"bar"];
NSMutableArray *frasi = [NSMutableArray array];
[frasi addObject:firstArray];
[frasi addObject:secondArray];
NSMutableArray *array = [NSMutableArray arrayWithObjects:[frasi objectAtIndex:[button isSelected]], nil];
NSString *q = [array objectAtIndex: (arc4random()% [array count] )];
NSString *lab = [NSString stringWithFormat:@"%@", q];
self.label.text = lab;
一切正常,但新标签是
( "foo" )
而不仅仅是 foo (不带引号)......可能我在最后一段代码中搞砸了......
泰