目标c,我想在我的stroyboard中使用SWRevealViewController

时间:2015-10-22 10:42:05

标签: objective-c iphone json xcode storyboard

我是Objective-C.的新手。我想加载左侧的meny。为此,我使用SWRevealViewController。 enter image description here 但我很愚蠢地加载我的代码

#import "ContactsTableViewController.h"
#import "CustomCell.h"
#import "UIImageView+WebCache.h"
#import "SWRevealViewController.h"

#define homePagesNews @"http://198.72.115.125/~pratidin/api/topnews"
#define jatioNews @"http://198.72.115.125/~pratidin/api/categorynews/4"

@interface ContactsTableViewController (){
    NSMutableArray *res;
}

@property (nonatomic, strong) NSArray *contactsArray;
@property (nonatomic, strong) NSArray *newsArray;
@property (nonatomic, strong) NSDictionary *details;



@end

@implementation ContactsTableViewController

@synthesize contactsArray, details,newsArray;


- (void)viewDidLoad {
    [super viewDidLoad];

//    _barButton.target = self.revealViewController;
//    _barButton.action = @selector(revealToggle:);
//    
//    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

    NSLog(@"My");
     self.view.backgroundColor = [UIColor whiteColor];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"contacts" ofType:@"plist"];
    contactsArray  = [NSArray arrayWithContentsOfFile :path];    
    [self GetHomePageData];

}

-(void)GetHomePageData{

    NSString *urlString   = [NSString stringWithFormat:@"%@",homePagesNews];
    NSURL *url            = [[NSURL alloc]initWithString:urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLResponse *response;
    NSData *GETReply      = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
    res = [NSJSONSerialization JSONObjectWithData:GETReply options:NSJSONReadingMutableLeaves|| NSJSONReadingMutableContainers error:nil];
    NSLog(@"%@",res);

    for (int i=0; i< res.count; i++){
        NSLog(@"item-id :%@",[[res objectAtIndex:i] objectForKey:@"item_id"]);
        NSLog(@"datetime %@",[[res objectAtIndex:i] objectForKey:@"title"]);
        NSLog(@"main_url %@",[[res objectAtIndex:i] objectForKey:@"summery"]);
        NSLog(@"main_url %@",[[res objectAtIndex:i] objectForKey:@"main_url"]);
        NSLog(@"main_url %@",[[res objectAtIndex:i] objectForKey:@"featured_image"]);
        NSLog(@"main_url %@",[[res objectAtIndex:i] objectForKey:@"main_url"]);
        NSLog(@"----------------------------------------------------------------");
    }

}



- (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 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
   // return [contactsArray count];
    return  res.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier =@"Cell";
    CustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    details = res[indexPath.row];

    NSString *titleNews = details[@"title"];
    NSString *newsDateTime = details[@"datetime"];
    NSString *NewsImageName = details[@"featured_image"];

    //UIImage *image = [UIImage imageNamed:NewsImageName ];
   // UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:NewsImageName]]];

    customCell.customFirstNameLabel.text = titleNews;
    customCell.customLastnameLabel.text = newsDateTime;
    //customCell.customImageView.image =image;

    NSURL *imageUrl=[details valueForKey:@"featured_image"];

    [customCell.customImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"no_image.png"]];

    return customCell;
}

SotryBoard图片

enter image description here

如果有人解决我的问题,那就太好了。提前致谢

2 个答案:

答案 0 :(得分:2)

你这样做的方式似乎完全没错。你应该在storyBoard中有一个SWRevealViewController类的ViewController,就像这个tutorial_1tutorial_2一样。通过这些。< / p>

然后,如果您使用的是最新版本的SWRevealViewController(版本2.4.0),那么现在有两个不同的segue类SWRevealViewControllerSegueSetControllerSWRevealViewControllerSeguePushController。第一个用于将revealViewController与故事板中的初始控制器一起设置。第二个用于通过动画将控制器推到前面。

所以你应该使用SWRevealViewControllerSegueSetController segue将主屏幕与上面提到的ViewController连接起来并命名为sw_front,你应该使用SWRevealViewControllerSegueSetController segue将侧面菜单与上面提到的ViewController连接起来并应将其命名为sw_rear

多数民众赞成。然后将ViewController(带有SERevealViewController类)作为初始的ViewController。

此外,来自侧边菜单viewcontroller的任何segue都应为 SWRevealViewControllerSeguePushController

答案 1 :(得分:1)