我正在 iOS SDK 中创建一个程序,其中有一组按钮。单击按钮时,其标题将添加到数组中,并且数组显示在分配的标签中。
当我尝试创建删除和清除按钮时,会出现错误消息。它们出现在 function_builder = function_builder.removeLastObject; 和 function_builder = function_builder.removeAllObjects; .m 文件的行。错误消息是相同的:从不兼容的类型“void”分配给“NSMutableArray *_strong”。我该如何解决?感谢您的任何帮助
这是.h文件:
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@property (nonatomic,strong) IBOutlet UILabel *equation_field;
@property (nonatomic) NSMutableArray *function_builder;//declare array//
@property(nonatomic, readonly, retain) NSString *currentTitle;//declare button titles//
@end
这是 .m 文件:
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize equation_field;
@synthesize currentTitle;
@synthesize function_builder;
NSMutableArray *function_builder;//create the array name//
- (IBAction)functionButtonPress:(UIButton *)sender {//code for all buttons except delete and clear//
[function_builder addObject: sender.currentTitle];//when button is pressed, its title is added to the array//
self.equation_field.text = function_builder.description;//the contents of the array appear in the assigned label//
}
- (IBAction)delete:(UIButton *)sender {//create delete button//
function_builder = function_builder.removeLastObject; //ERROR OCCURRING HERE: Assigning to 'NSMutableArray *_strong' from incompatible type 'void'//
}
- (IBAction)clear:(UIButton *)sender{//create clear button//
function_builder = function_builder.removeAllObjects;//ERROR OCCURRING HERE: Assigning to 'NSMutableArray *_strong' from incompatible type 'void'//
}
- (void)viewDidLoad {
function_builder = [[NSMutableArray alloc] init];//initialize array//
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end