Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @interface MasterViewController (){
- NSArray *feedObjects;
- NSMutableArray *feedArray;
- }
- @property NSMutableArray *objects;
- @end
- @implementation MasterViewController
- - (void)awakeFromNib {
- [super awakeFromNib];
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
- self.clearsSelectionOnViewWillAppear = NO;
- self.preferredContentSize = CGSizeMake(320.0, 600.0);
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- feedArray = [[NSMutableArray alloc]init];
- [self configureRestKit];
- // Do any additional setup after loading the view, typically from a nib.
- self.navigationItem.leftBarButtonItem = self.editButtonItem;
- UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
- self.navigationItem.rightBarButtonItem = addButton;
- self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(RKResponseDescriptor *)responseDescriptor {
- RKObjectMapping *bodyMapping = [RKObjectMapping mappingForClass:[BaseClass class]];
- [bodyMapping addAttributeMappingsFromArray:@[@"body",@"title"]];
- RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:bodyMapping method:RKRequestMethodAny pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
- return responseDescriptor;
- }
- -(void)configureRestKit{
- NSURL *baseURL = [NSURL URLWithString:@"http://urlExample"];
- NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];
- RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[[self responseDescriptor]]];
- [objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
- feedObjects = mappingResult.array;
- [feedArray addObject:feedObjects];
- [self.tableView reloadData];
- RKLogInfo(@"Load collection of Feeds: %@", mappingResult.array);
- } failure:^(RKObjectRequestOperation *operation, NSError *error) {
- RKLogError(@"Operation failed with error: %@", error);
- }];
- [objectRequestOperation start];
- }
- #pragma mark - Table View
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return feedArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
- NSMutableArray *feedarray = feedArray[indexPath.row];
- BaseClass *feedO = feedarray[0];
- cell.textLabel.text = [NSString stringWithFormat:@"%@",feedO.title];
- return cell;
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- // Return NO if you do not want the specified item to be editable.
- return YES;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement