方法调用的参数过多,应为1,有2个?(Xcode) [英] Too many arguments to method call, expected 1, have 2?(Xcode)

查看:116
本文介绍了方法调用的参数过多,应为1,有2个?(Xcode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有许多与此类似的问题,但是缺少答案,并且每个项目的答案各不相同. 我有这个错误 方法调用的参数过多,预​​期为1,有2个?" 但是在我使用的以前的阵列上没有发生此错误?这可能是代码的问题,但我不确定吗?我经历了寻找可能影响它的其他错误,但是没有运气. 下面是我的编码,

There are many other similar questions to this one, but there is a lack of answers and they vary for each project. I have this error 'Too many arguments to method call, expected 1, have 2?' But on the previous arrays that I used this error did not occur? it could be a problem with the code but i am unsure? I have went through searching for other errors that may influence it, but have had no luck. Below is my coding,

#import "MenuViewController.h"
#import "ECSlidingViewController.h"

@interface MenuViewController ()

@property (strong, nonatomic) NSArray *menu;
@property (strong, nonatomic) NSArray *section1;
@property (strong, nonatomic) NSArray *section2;
@property (strong, nonatomic) NSArray *section3;


@end

@implementation MenuViewController

@synthesize menu, section1, section2, section3;


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    self.section1 = [NSArray arrayWithObjects:@"News Feed", @"Buy Shares", @"Sell Shares", nil];

    self.section2 = [NSArray arrayWithObjects:@"Finances", @"Current Holdings", @"Trading History", nil];

    ***self.section3 = [NSArray arrayWithObject:@"Leaderboard", nil];***

    self.menu = [NSArray arrayWithObjects:self.section1, self.section2, self.section3, nil];


    [self.slidingViewController setAnchorRightRevealAmount:200.0f];
    self.slidingViewController.underLeftWidthLayout = ECFullWidth;

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return [self.menu count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.

    if (section == 0) {

        return [self.section1 count];

    } else if (section == 1) {

        return [self.section2 count];

    } else if (section == 2) {

        return  [self.section3 count];

    }


}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {


    if (section == 0) {

        return @"Stock Market";

    } else if (section == 1) {

        return @"Portfolio";

    } else if (section == 2) {

        return  @"Options";

    }


}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }

    if (indexPath.section == 0) {

        cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.section1 objectAtIndex:indexPath.row]];

    } else if (indexPath.section == 1) {


        cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.section2 objectAtIndex:indexPath.row]];
    } else if (indexPath.section == 2) {


        cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.section3 objectAtIndex:indexPath.row]];
    }





    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];

     */

    UIViewController *newTopViewController;


    if (indexPath.section == 0) {

        NSString *identifier = [NSString stringWithFormat:@"%@", [self.section1 objectAtIndex:indexPath.row]];

        newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];

    } else if (indexPath.section == 1) {

        NSString *identifier = [NSString stringWithFormat:@"%@", [self.section2 objectAtIndex:indexPath.row]];

        newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];

    } else if (indexPath.section == 2) {

        NSString *identifier = [NSString stringWithFormat:@"%@", [self.section3 objectAtIndex:indexPath.row]];

        newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];

    }




    [self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
        CGRect frame = self.slidingViewController.topViewController.view.frame;
        self.slidingViewController.topViewController = newTopViewController;
        self.slidingViewController.topViewController.view.frame = frame;
        [self.slidingViewController resetTopView];
    }];


}

@end

任何帮助将不胜感激.谢谢.错误出现在我放置"***"的位置

Any help would be much appreciated. Thanks. The error appears where i have placed '***'

推荐答案

如果您指出了哪条线引起了问题,那将是很好的,但是我想我还是找到了:

It would have been nice if you had indicated which line was causing problems, but I think I found it anyway:

[NSArray arrayWithObject:@"Leaderboard", nil];

arrayWithObject仅需要一个对象,而不是用逗号分隔的对象数组.请改用以下内容:

arrayWithObject only expects an object, not a comma-separated array of objects. Use the following instead:

[NSArray arrayWithObject: @"Leaderboard"];

或者,为了与周围的代码更加一致,请使用

Or, to be more consistent with the surrounding code, use

[NSArray arrayWithObjects: @"Leaderboard", nil];

这篇关于方法调用的参数过多,应为1,有2个?(Xcode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆