1

我以前在另一个项目上做过这个,然后让它工作,但我不知道为什么我的这段程序不起作用。它显示没有任何 plist 数据的表格。请看一下我的代码,看看你是否能发现我犯了错误的地方,谢谢。

#import "MarketViewController.h"
#import "SecondViewController.h"
#import "ECSlidingViewController.h"
#import "MenuViewController.h"

@interface MarketViewController ()

@end

@implementation MarketViewController
@synthesize shares, shareValues, number, shareName;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{


    self.navigationItem.title = @"Stock Market";
    NSString *sharesFile = [[NSBundle mainBundle] pathForResource:@"Shares" ofType:@"plist"];

    shares = [[NSDictionary alloc] initWithContentsOfFile: sharesFile];
    shareValues = [shares objectForKey:@"Share Values"];
    shareName = [shares objectForKey:@"Share Names"];

    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.layer.shadowOpacity = 0.75f;
    self.view.layer.shadowRadius = 10.0f;
    self.view.layer.shadowColor = [UIColor blackColor].CGColor;


    if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
        self.slidingViewController.underLeftViewController  = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
    }


    [self.view addGestureRecognizer:self.slidingViewController.panGesture];

    self.menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _menuBtn.frame = CGRectMake(8, 10, 34, 24);
    [_menuBtn setBackgroundImage:[UIImage imageNamed:@"menuButton.png"] forState:UIControlStateNormal];
    [_menuBtn addTarget:self action:@selector(revealMenu:) forControlEvents:UIControlEventTouchUpInside];


    [self.view addSubview:self.menuBtn];



}

//Table View

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [shares count];
}

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


    NSString *nameOfShare = [shareName objectAtIndex:[indexPath row]];
    NSString *valueOfShare = [shareValues objectAtIndex:[indexPath row]];
    cell.detailTextLabel.text = valueOfShare;
    cell.textLabel.text = nameOfShare;
    return cell;
    self.title = @"Stock Market";


}

- (IBAction)revealMenu:(id)sender
{
    [self.slidingViewController anchorTopViewTo:ECRight];
}

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

@end

我的h。文件如下:

#import <UIKit/UIKit.h>

@interface MarketViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>


@property (strong, nonatomic) UIButton *menuBtn;
@property (nonatomic, readonly) NSDate *CurrentDate;
@property (nonatomic, strong) NSDictionary *shares;
@property (nonatomic, strong) NSArray *shareValue;
@property (nonatomic, strong) NSArray *number;
@property (nonatomic, strong) NSArray *shareName;
- (NSString*)filePath;
- (void)openDB;



@end
4

0 回答 0