我正在iOS SDK中创建一个程序,其中有一组按钮。当单击按钮时,其标题将被添加到数组中,并且该数组将显示在已分配的标签中。XCode中的数组管理帮助?
当我尝试创建删除和清除按钮时,显示错误消息。它们出现在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
非常感谢你 – user1520507 2012-07-12 17:18:43