Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. @interface MasterViewController (){
  2.  
  3. NSArray *feedObjects;
  4. NSMutableArray *feedArray;
  5.  
  6. }
  7.  
  8. @property NSMutableArray *objects;
  9. @end
  10.  
  11. @implementation MasterViewController
  12.  
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
  16. self.clearsSelectionOnViewWillAppear = NO;
  17. self.preferredContentSize = CGSizeMake(320.0, 600.0);
  18. }
  19. }
  20.  
  21. - (void)viewDidLoad {
  22.  
  23.  
  24. [super viewDidLoad];
  25. feedArray = [[NSMutableArray alloc]init];
  26.  
  27. [self configureRestKit];
  28. // Do any additional setup after loading the view, typically from a nib.
  29. self.navigationItem.leftBarButtonItem = self.editButtonItem;
  30.  
  31. UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
  32. self.navigationItem.rightBarButtonItem = addButton;
  33. self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
  34. }
  35.  
  36. - (void)didReceiveMemoryWarning {
  37. [super didReceiveMemoryWarning];
  38. // Dispose of any resources that can be recreated.
  39. }
  40.  
  41. -(RKResponseDescriptor *)responseDescriptor {
  42.  
  43. RKObjectMapping *bodyMapping = [RKObjectMapping mappingForClass:[BaseClass class]];
  44. [bodyMapping addAttributeMappingsFromArray:@[@"body",@"title"]];
  45.  
  46. RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:bodyMapping method:RKRequestMethodAny pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
  47.  
  48. return responseDescriptor;
  49. }
  50.  
  51. -(void)configureRestKit{
  52.  
  53. NSURL *baseURL = [NSURL URLWithString:@"http://urlExample"];
  54. NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];
  55.  
  56. RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[[self responseDescriptor]]];
  57.  
  58. [objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
  59.  
  60. feedObjects = mappingResult.array;
  61. [feedArray addObject:feedObjects];
  62. [self.tableView reloadData];
  63.  
  64. RKLogInfo(@"Load collection of Feeds: %@", mappingResult.array);
  65.  
  66. } failure:^(RKObjectRequestOperation *operation, NSError *error) {
  67. RKLogError(@"Operation failed with error: %@", error);
  68. }];
  69.  
  70. [objectRequestOperation start];
  71. }
  72.  
  73. #pragma mark - Table View
  74.  
  75. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  76. return 1;
  77. }
  78.  
  79. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  80.  
  81. return feedArray.count;
  82. }
  83.  
  84. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  85. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  86.  
  87. NSMutableArray *feedarray = feedArray[indexPath.row];
  88. BaseClass *feedO = feedarray[0];
  89.  
  90. cell.textLabel.text = [NSString stringWithFormat:@"%@",feedO.title];
  91.  
  92. return cell;
  93. }
  94.  
  95. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  96. // Return NO if you do not want the specified item to be editable.
  97. return YES;
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement