我正在创建一个具有随机标签生成器的应用程序,但我发现它有时会重复。我想知道我是否可以立即解决这个问题,但我不知道该怎么做?任何帮助将不胜感激。我提供了我的 .h 和 .m 文件。这是我的.h
#import <UIKit/UIKit.h>
#import "MessageUI/MessageUI.h"
#import "Social/Social.h"
#import "Accounts/Accounts.h"
#import <iAd/iAd.h>
@interface ViewController2 : UIViewController <MFMessageComposeViewControllerDelegate, ADBannerViewDelegate> {
SLComposeViewController *mySLComposerSheet;
//label that is being randomly generated.
IBOutlet UILabel *label;
}
-(IBAction)randomButton;
-(IBAction)randomButton2;
-(IBAction)SendSMS:(id)sender;
-(IBAction)PostToFacebook:(id)sender;
- (IBAction)SendATweet:(id)sender;
@end
这是我的.m
-(IBAction)randomButton {
int randomText = rand() %151;
switch (randomText) {
case 0:
label.text = @"1";
break;
case 1:
label.text = @"2";
break;
case 2:
label.text = @"3";
break;
case 3:
label.text = @"4";
break;
case 4:
label.text = @"5";
break;
case 5:
label.text = @"6";
break;
case 6:
label.text = @"7";
break;
case 7:
label.text = @"";
break;
case 8:
label.text = @"8";
break;
case 9:
label.text = @"9";
break;
case 10:
label.text = @"10";
break;
case 11:
label.text = @"11";
//ect.....
提前致谢。