其他人請檢查我的代碼嗎?必須有一些錯誤。還沒有答案。任何人有任何其他想法?我收到了SecondViewController.m底部標題中的錯誤消息。我不確定爲什麼,我試圖查找它,但我找不到任何東西。我認爲我宣佈了「showDiceNumber」是什麼,但可能不是。這是我的應用程序的第二頁,但這不應該導致問題,因爲錯誤是在第二個視圖控制器。我非常感謝審查代碼並在這種情況下幫助我的人。非常感謝!「DiceView」沒有可見的@interface聲明選擇器「showDiceNumber」。
(順便說一句,我拿出超視做負載和繪圖代碼,因爲他們是無用的,佔去了太多的空間,他們在我在Xcode編碼雖然。)
SecondViewController.h -
#import <UIKit/UIKit.h>
#import "DiceView.h"
@interface SecondViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *rollButton;
@property (strong, nonatomic) IBOutlet UILabel *sumLabel;
@property (strong, nonatomic) IBOutlet DiceView *firstDiceView;
@property (strong, nonatomic) IBOutlet DiceView *secondDiceView;
@end
SecondViewController.m -
#import "SecondViewController.h"
#import "DiceDataController.h"
@interface SecondViewController()
@end
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (IBAction)rollClicked:(id)sender {
DiceDataController *diceController = [[DiceDataController alloc] init];
int firstNumber = [diceController getDiceNumber];
int secondNumber = [diceController getDiceNumber];
[self.firstDiceView showDiceNumber:firstNumber]; <---- error*
[self.secondDiceView showDiceNumber:secondNumber]; <----- error*
}
@end
DiceView.h -
#import <UIKit/UIKit.h>
@interface DiceView : UIView
#pragma mark - Properties
@property (strong, nonatomic) UIImageView *diceImageView;
#pragma mark - Methods
- (void)showDiceNumber:(int)num;
@end
DiceView.m-
#import "DiceView.h"
@implementation DiceView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code
// create uiimageview and assign it to our property
self.diceImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
// add the imageview to the view
[self addSubview:self.diceImageView];
}
return self;
}
- (void)showDiceNumber:(int)num
{
// construct filename based on input param
NSString *fileName = [NSString stringWithFormat:@"dice%d.png", num];
// set the image to the uiimageview
self.diceImageView.image = [UIImage imageNamed:fileName];
}
@end
DiceDataController.h-
#import <Foundation/Foundation.h>
@interface DiceDataController : NSObject
-(int)getDiceNumber;
@end
DiceDataController.m-
#import "DiceDataController.h"
@implementation DiceDataController
-(int)getDiceNumber
{
int r = (arc4random() % 6) +1;
return r;
}
@end
有人請幫忙嗎?這可能是愚蠢的,但我找不到錯誤。 – user3496401
@MHHaze你可以看一下嗎?你以前幫過我。 – user3496401
你發佈的內容看起來正確。有時Xcode會感到困惑。嘗試關閉您的項目並退出Xcode。然後重新啓動,看看它是否有幫助。 – rmaddy