gpt4 book ai didi

objective-c - 错误: incompatible types in assignment

转载 作者:行者123 更新时间:2023-12-03 16:24:33 25 4
gpt4 key购买 nike

我正在编写一些 Objective-C 代码,但我不明白为什么这不起作用:

buttonRect = CGRectMake(0,0,100.0,100.0);//error:incompatible types in assignment
CGRect newFrame = CGRectInset(buttonRect, -0.2, -0.2);//error:incompatible type for argument 1 of CGRectInset
button.frame = newFrame;

buttonRect是一个在我的类中定义为实例变量的CGRect,而button是一个也定义为实例变量的UIButton。为什么这不起作用?我的头文件:

//
// MyViewController.h
// HelloWorld
//
// Created by RCIX on 7/10/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface MyViewController : UIViewController {
UITextField *textField;
UILabel *label;
NSString *string;
UIButton *button;
CGRect *buttonRect;
}

@property (nonatomic, assign) CGRect *buttonRect;
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) NSString *string;

- (IBAction)helloButtonDown:(id)sender;
- (IBAction)helloButtonUp:(id)sender;

@end

最佳答案

buttonRect 被声明为 CGRect * — 即指向 CGRect 的指针。去掉碎片,一切都会好起来的。

关于objective-c - 错误: incompatible types in assignment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1122906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com