2013-04-04 83 views
0

有這一個許多其他類似的問題,但有一個得不到答案,他們改變了每一個項目。 我有這個錯誤 '太多的方法調用參數,預期1,有2?' 但在以前的陣列,我用這個錯誤沒有發生?它可能是代碼的問題,但我不確定?我已經通過尋找可能影響它的其他錯誤,但沒有運氣。 下面是我的編碼,太多參數的方法調用,預計1,有2個?(Xcode中)

#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 

任何幫助將非常感激。謝謝。出現錯誤的位置我已經把「***」

Screenshot

+0

這將是您更容易得到答案,如果你想至少有標記你的問題您正在使用的語言名稱。 – Voitcus 2013-04-04 13:48:53

回答

4

這本來是很好,如果你曾表示該行是造成問題,但我想我找到它無論如何:

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

arrayWithObject只需要一個對象,而不是逗號分隔的對象數組。使用以下代替:

[NSArray arrayWithObject: @"Leaderboard"]; 

或者,要與周圍的代碼更一致,使用

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

對不起,我正在指出,我沒有意識到我忘了。如果我包含多個字符串,您的建議是否仍然有效? – 2013-04-04 13:51:21

+1

@JasonTaylor我假設你想使用'arrayWithObjects:'(注意's'),因爲這就是它上下使用的行。 – Xymostech 2013-04-04 13:52:56

+0

對於多個字符串,您可以使用arrayWithObjects(注意s),就像您在3個類似的行上做的一樣。 [這裏](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html)是解釋兩種方法之間差異的文檔。 – 2013-04-04 13:53:48

相關問題