I'm new to iOS development and am currently studying from video tutorials. I came across a problem with quite a simple app I'm experimenting on.
The problem is with loading pictures to UIImage in a split view control iPad app. The app is based on the XCode master-detail application template. I created an array with NSObject variables and two properties.
#interface Burger : NSObject
#property (nonatomic) NSString *name;
#property (nonatomic) NSString *filename;
#end
- (void)viewDidLoad {
[super viewDidLoad];
photos = [[NSMutableArray alloc]init];
Burger *pic = [[Burger alloc]init];
pic.name = #"Bacon";
pic.filename = #"burger-bacon";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Cheese";
pic.filename = #"burger-cheddar";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Hawaii";
pic.filename = #"burger-hawaii";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Koko z jajkiej kurzym";
pic.filename = #"burger-jajo";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Kozi ser";
pic.filename = #"burger-kozi";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Łosoś";
pic.filename = #"burger-losos";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Vege (Soczewica)";
pic.filename = #"burger-soczewica";
[photos addObject:pic];
}
I want the UImageView nested in DetailView to display a picture of the object chosen in the MasterView controller. I got it to display the pictures in the MasterView table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Burger *current = [photos objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageNamed:[current filename]];
[cell.imageView setImage:image];
self.title = self.currentPhoto.name;
cell.textLabel.text = [current name];
cell.detailTextLabel.text = [current price];
return cell;
}
and it also works when I point to a specific file name:
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
UIImage *image = [UIImage imageNamed: #"burger-bacon"];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
}
}
but when I try to show the picture of the chosen element like this:
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
UIImage *image = [UIImage imageNamed: self.currentPhoto.filename];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
}
}
I get these few lines in the debug area:
2015-06-23 12:13:25.964 SlowFoodiPad[22177:744765] CUICatalog: Invalid asset name supplied: (null)
which means the segues work and the photo files seem to be fine. There seem to be a problem with pointing to the right file to display. Any ideas how to fix it?
OK, I managed to solve the problem partially. I edited prepareForSegue method of MasterViewController:
DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
Burger *c = photos [indexPath.row];
[controller setDetailItem:c];
//this line helped
[controller setCurrentPhoto:c];
The appropriate photos now show, although the debug area keeps showing me this message:
CUICatalog: Invalid asset name supplied: (null)
two identical lines each time I tap on an element in the MasterView table.
Right now it's unclear when "-(void)configureView" is being called. My guess, based on your issue, is that it's actually called before prepareForSegue. Or at least, the very first time, it's being called before you actually have an image. You are checking for "if (self.detailItem)" but you are not checking for if (self.currentPhoto).
So probably the first time configure view is called, there is no self.currentPhoto so it can't be set. Then when the segue is actually prepared (prepareForSegue:) you set the current photo, so then when configure view is called again, it's there.
If you paste more of your view controller code that shows what triggers the segue (probably it's just the storyboard but unclear from what you have above) and when configureView, then we'd know for sure if my guess is correct.
OK, there's some progress. Now I only get two lines of this message and only at initial start of the app:
CUICatalog: Invalid asset name supplied: (null)
I commented out few lines here. Can you see anything else that is causing problems?
- (void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView {
// Update the user interface for the detail item.
// if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
// UIImage *image = [UIImage imageNamed:self.currentPhoto.filename];
// [self.currentImage setImage:image];
}
//}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *image = [UIImage imageNamed:self.currentPhoto.filename];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
self.detailDescriptionLabel.text = [self.detailItem notes];
// [self configureView];
}
Here's the prepareForSegue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Burger *c = photos [indexPath.row];
[controller setDetailItem:c];
//adding this line helped
[controller setCurrentPhoto:c];
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
controller.navigationItem.leftItemsSupplementBackButton = YES;
}
}
Related
Can anyone please help me here? scenario is:
I have a view controller, page view controller, and a content for page view controller.
The app is to initially load 3 pages of images, and on the 3rd page a button will then appear. if pressed it'll be directed to the main menu page.
all images are loaded from parse.
I previously had a separate program for page view controller and another for parse image loader, executed perfectly. however when I combine both together it fails. based on what I understand is that, images from parse are stored as NSData. however, in my page view controller, i'm using index to load the images. I tried converting NSData to NSArray using KeyedAchiver however it couldn't work.
I also notice that my image loaded from parse doesn't come in the sequence I want. So, if possible, please help to advise on this!
below are the codes. thanks in advance!
//***********************view controller
#import "ViewController.h"
#import <parse/parse.h>
#interface ViewController ()
#end
#implementation ViewController
#synthesize parseImageData,pageImages; //UIImage, NSData
- (void)viewDidLoad
{
[super viewDidLoad];
// Create the data model
// _pageTitles = #[#"New York Cheese", #"Vanilla Cake", #"Green Tea Cake", #"Choc Indulgence"];
// _pageImages = #[#"pic1.png", #"pic2.png", #"pic3.png", #"pic4.png"];
_pageTitles = #[#"New York Cheese", #"Vanilla Cake"];
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
NSLog(#"viewcontroller.m viewdidload complete");
}
- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count])) {
NSLog(#"out of range!");
return nil;
}
NSLog(#"viewcontroller.m update index");
//add my own parse program
PFQuery *query = [PFQuery queryWithClassName:#"Pictures"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
NSLog(#"picture queried");
NSLog(#"array %#",objects);
NSArray *imageFilesArray = [[NSArray alloc]initWithArray:objects];
PFObject *imageObject = [imageFilesArray objectAtIndex:index];
PFFile *imageFile = [imageObject objectForKey:#"imageFile"];
// scrolling.hidden = NO;
// [scrolling startAnimating];
NSLog(#"pffile %#",imageFile);
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if(!error){
// scrolling.hidden = YES;
//imageView.image = [UIImage imageWithData:data];
pageImages = data;
parseImageData = [UIImage imageWithData:data];
NSLog(#"nsdata translated %#",parseImageData);
// pageContentViewController.imageFile = data;
}
}];
}}];
// Create a new view controller and pass suitable data.
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageContentViewController"];
// pageContentViewController.imageFile = self.pageImages[index];
pageContentViewController.titleText = self.pageTitles[index];
NSLog(#"self.pagetitles[index]");
//pageContentViewController.imageFile = parseImageData;
NSArray *pageImagesArray = [NSKeyedArchiver archivedDataWithRootObject:pageImages];
pageContentViewController.imageFile = pageImagesArray[index];
NSLog(#"pagecontentviewcontroller.imagefile is %#",pageContentViewController.imageFile);
NSLog(#"self.parseImageData %lu",(unsigned long)index);
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
//*****************PAGE CONTENT CONTROLLER PART
#import "PageContentViewController.h"
#import <parse/parse.h>
#interface PageContentViewController ()
#end
#implementation PageContentViewController
#synthesize imageFile,titleText,backgroundImageView; //NSData, NSString, IBOutlet UIImage
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//self.backgroundImageView.image = [UIImage imageWithData:imageFile];
backgroundImageView.image = [UIImage imageWithData:imageFile];
self.titleLabel.text = self.titleText;
NSLog(#"Image supposed be loaded...%#",imageFile);
NSLog(#"title supposed be loaded...%#",titleText);
}
I am trying to parse a JSON image url and display it in a view. I have no trouble getting the image url and converting it to UIImage. When the user selects a row in the tableview a new view is presented and displays the image from the url. The issue is that the image is different every time the view loads. I NSLog the url and it is the same every time I select the row. I can not see where I am going wrong here.
This is the view that gets the image url and converts it to an image:
// ViewController.m
#import "ViewController.h"
#import "DetailViewController.h"
#interface ViewController ()
#end
#implementation ViewController
...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//imgURL = [imgURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *imageUrl = [NSURL URLWithString:[[_model.bars objectAtIndex:indexPath.row] objectForKey:#"image_url"]];
//NSLog(#"%#", imageUrl);
UIImage *barImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageUrl]];
NSLog(#"%#", imageUrl);
_model.barAddress = [NSString stringWithFormat: #"%# %# %#", [[_model.bars objectAtIndex:indexPath.row] objectForKey:#"address"],
[[_model.bars objectAtIndex:indexPath.row] objectForKey:#"state"],
[[_model.bars objectAtIndex:indexPath.row] objectForKey:#"zip"]];
_detailData.selectedBarName = [[_model.bars objectAtIndex:indexPath.row] objectForKey:#"name"];
_detailData.selectedBarAddress = _model.barAddress;
_detailData.selectedBarPhoneNumber = [[_model.bars objectAtIndex:indexPath.row] objectForKey:#"phone"];
_detailData.selectedBarImage = barImage;
NSLog(#"%#", _detailData.selectedBarImage);
if ([[segue identifier] isEqualToString:#"detailSeg"]) {
DetailViewController *controller = (DetailViewController *)segue.destinationViewController;
controller.barNameObject = _detailData.selectedBarName;
controller.barAddressObject = _detailData.selectedBarAddress;
controller.barPhoneNumberObject = _detailData.selectedBarPhoneNumber;
controller.barImageObject = _detailData.selectedBarImage;
NSLog(#"%#", controller.barImageObject);
}
}
#end
This is the view that displays the image.
// DetailViewController.m
#import "DetailViewController.h"
#import "DetailViewData.h"
#interface DetailViewController ()
#end
#implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
//_detailData = [[DetailViewData alloc] init];
_model = [[Model alloc] init];
// Do any additional setup after loading the view from its nib.
_barName.text = self.barNameObject;
_barAddress.text = self.barAddressObject;
_barPhone.text = self.barPhoneNumberObject;
_barPhoto.image = self.barImageObject;
}
Your code is absolutely correct.
So, I checked the web service response. If you check any of the image_URl
say http://lorempixel.com/900/500/sports/?v=-417059871 , it is loading different images all the time. I think the issue is not in your code but in the url, just paste it in your browser and refresh, each time it loads different images.
I wanted to add this as a comment but I don't have enough reputation as of now.
I've built an iOS 7 app using storyboards. Within my offersViewController I have a UIView and a UITableView. The UIView acts as a subview that displays a loading message while my feed is been parsed. Once complete the subview is removed and my parsed data is presented in my UITableView.
#interface OffersViewController ()
#end
#implementation OffersViewController
#synthesize loadingView;
MoreCobaltOffers *currentFeed;
AppDelegate *appDelegate;
- (void)viewDidAppear:(BOOL)animated
{
[self.tableView addSubview:loadingView];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Navigation"]];
CustomStringParser *customStringParser = [[CustomStringParser alloc] init];
// Download and parse XML data
RXMLElement *rxml = [RXMLElement elementFromXMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.myrssfeed.com"]]];
// Create an reference to AppDelegate
appDelegate = [[UIApplication sharedApplication] delegate];
// Create an array to store each feed
appDelegate.offersFeeds = [[NSMutableArray alloc] init];
// Loop Through XML Data
[rxml iterate:#"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:#"item" usingBlock:^(RXMLElement *repElement) {
// Assign element to string
NSString *title = [repElement child:#"title"].text;
NSString *subtitle = [repElement child:#"tagline"].text;
NSString *description = [repElement child:#"description"].text;
NSString *imageurl = [repElement child:#"image"].text;
NSString *address = [repElement child:#"address"].text;
// Assign element value to MoreCobalt.h propertys
currentFeed = [MoreCobaltOffers alloc];
currentFeed.title = title;
currentFeed.imageurl = imageurl;
currentFeed.addressline = address;
// DESCRIPTION FORMATTING
description = [customStringParser parseHTML:description];
description = [customStringParser parseLinesMultiple:description];
description = [customStringParser removeSocialSignifiers:description];
description = [customStringParser appendTermsOfUse:description];
currentFeed.description = description;
// SUBTITLE FORMATTING
subtitle = [customStringParser parseHTML:subtitle];
subtitle = [customStringParser parseLinesSingle:subtitle];
subtitle = [customStringParser removeSocialSignifiers:subtitle];
currentFeed.subtitle = subtitle;
// Add a new object to the feeds array
[[appDelegate offersFeeds] addObject:currentFeed];
}];
//Remove the loading screen
[loadingView removeFromSuperview];
//Show table data, if this is not here the table is empty.
[self.tableView reloadData];
}];
}
When I run the app the loading screen appears and then the table is displayed with data. If I navigate away from this view controller to another tab and then navigate back the table will flash. Not very good user experience.
The line of code responsible is [self.tableView reloadData];. I need this in or table becomes empty. What am I doing wrong?
ViewWillAppear is called any time the view appears. In order for the table not to reload each time, move the code inside viewDidAppear.
For showing the loading view only one time move the parsing to another method like:
- (void)parseFeed {
[self.loadingIndicator startAnimating];
self.loadingIndicator.hidesWhenStopped = YES;
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Navigation"]];
CustomStringParser *customStringParser = [[CustomStringParser alloc] init];
// Download and parse XML data
RXMLElement *rxml = [RXMLElement elementFromXMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.morecobalt.co.uk/rss/?t=offers"]]];
// Create an reference to AppDelegate
appDelegate = [[UIApplication sharedApplication] delegate];
// Create an array to store each feed
appDelegate.offersFeeds = [[NSMutableArray alloc] init];
// Loop Through XML Data
[rxml iterate:#"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:#"item" usingBlock:^(RXMLElement *repElement) {
// Assign element to string
NSString *title = [repElement child:#"title"].text;
NSString *subtitle = [repElement child:#"tagline"].text;
NSString *description = [repElement child:#"description"].text;
NSString *imageurl = [repElement child:#"image"].text;
NSString *address = [repElement child:#"address"].text;
// Assign element value to MoreCobalt.h propertys
currentFeed = [MoreCobaltOffers alloc];
currentFeed.title = title;
currentFeed.imageurl = imageurl;
currentFeed.addressline = address;
// DESCRIPTION FORMATTING
description = [customStringParser parseHTML:description];
description = [customStringParser parseLinesMultiple:description];
description = [customStringParser removeSocialSignifiers:description];
description = [customStringParser appendTermsOfUse:description];
currentFeed.description = description;
// SUBTITLE FORMATTING
subtitle = [customStringParser parseHTML:subtitle];
subtitle = [customStringParser parseLinesSingle:subtitle];
subtitle = [customStringParser removeSocialSignifiers:subtitle];
currentFeed.subtitle = subtitle;
// Add a new object to the feeds array
[[appDelegate offersFeeds] addObject:currentFeed];
}];
[loadingView removeFromSuperview];
[self.loadingIndicator stopAnimating];
[self.tableView reloadData];
}];
[loadingView removeFromSuperview];
[self.loadingIndicator stopAnimating];
isFirstLoad = NO;
}
Declare a BOOL to check if it is first load and do this check:
-(void)viewDidAppear:(BOOL)animated {
if (isFirstLoad){
[self parseFeed];
}
[super viewDidAppear:animated];
}
Few things worth nothing:
You should extract all of that code for the parsing of your XML into another class. You should not be parsing data from XML inside of a view controller.
Right now you're running your network calls and parsing the XML data every time the view appears. What you might consider is only doing it when the view loads, thus running your code in viewDidLoad
Whenever you end up moving the code you might consider having a temporary local array and filling that with the XML return values, then using isEqualToArray to compare it to your property of values to see if its different. If it is, reload the table and set the property anew, if not, don't.
On my UIViewController I have a UIView and a UITableView. The UIView acts as a loading screen while my XML Parser (RaptureXML) is parsing table data. When its finished it shows the data in the UITableView.
However when I run the app and navigate to a different view controller and then back, the UITableView flashes due to [self.tableView reloadData]; If I take this out it does not display the data in the table. Can I move this somewhere else?
#interface OffersViewController ()
#end
#implementation OffersViewController
#synthesize loadingView;
MoreCobaltOffers *currentFeed;
AppDelegate *appDelegate;
- (void)viewDidAppear:(BOOL)animated
{
[self.tableView addSubview:loadingView];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Navigation"]];
CustomStringParser *customStringParser = [[CustomStringParser alloc] init];
// Download and parse XML data
RXMLElement *rxml = [RXMLElement elementFromXMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.morecobalt.co.uk/rss/?t=offers"]]];
// Create an reference to AppDelegate
appDelegate = [[UIApplication sharedApplication] delegate];
// Create an array to store each feed
appDelegate.offersFeeds = [[NSMutableArray alloc] init];
// Loop Through XML Data
[rxml iterate:#"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:#"item" usingBlock:^(RXMLElement *repElement) {
// Assign element to string
NSString *title = [repElement child:#"title"].text;
NSString *subtitle = [repElement child:#"tagline"].text;
NSString *description = [repElement child:#"description"].text;
NSString *imageurl = [repElement child:#"image"].text;
NSString *address = [repElement child:#"address"].text;
// Assign element value to MoreCobalt.h propertys
currentFeed = [MoreCobaltOffers alloc];
currentFeed.title = title;
currentFeed.imageurl = imageurl;
currentFeed.addressline = address;
// DESCRIPTION FORMATTING
description = [customStringParser parseHTML:description];
description = [customStringParser parseLinesMultiple:description];
description = [customStringParser removeSocialSignifiers:description];
description = [customStringParser appendTermsOfUse:description];
currentFeed.description = description;
// SUBTITLE FORMATTING
subtitle = [customStringParser parseHTML:subtitle];
subtitle = [customStringParser parseLinesSingle:subtitle];
subtitle = [customStringParser removeSocialSignifiers:subtitle];
currentFeed.subtitle = subtitle;
// Add a new object to the feeds array
[[appDelegate offersFeeds] addObject:currentFeed];
}];
[loadingView removeFromSuperview];
[self.tableView reloadData];
}];
}
You are adding the view before the TableView. Just change the order in the interface builder.
Here is you view hierarchy:
View
View
GrayActivity Indicator
Label - Loading
Table View
TableViewCell
Here is how is suppose to be:
View
Table View
TableViewCell
View
GrayActivity Indicator
Label - Loading
EDIT
Please remove this line `[loadingView setHidden:YES]; update your code to the following:
[rxml iterate:#"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:#"item" usingBlock:^(RXMLElement *repElement) {
.
.
.
[[appDelegate offersFeeds] addObject:currentFeed];
}];
dispatch_sync(dispatch_get_main_queue(), ^{
[loadingView setHidden:YES];
[self.table reloadData];
});
}];
restructure your code like this and i think it should work
// Loop Through XML Data
[rxml iterate:#"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:#"item" usingBlock:^(RXMLElement *repElement) {
[loadingView setHidden:No];
...
...
...
...
...
...
[loadingView setHidden:YES];
}];
}];
I have 3 VC. A which displays questions and answers. B is displayed when the Question is wrongly selected a C once the level is clear.
I am having an issue going from A-B & A-C.
Here is my code
#import "AViewController.h"
#import "BViewController.h"
#import "CViewController.h"
#interface AViewController ()
#end
Now here is the implementation code
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
BViewController *incorrect = [segue destinationViewController];
incorrect.currentQuestion = self.currentQuestion;}
//Here A is sending B information about which question was answered incorrectly i.e Current Question
- (void)viewDidLoad
{
[super viewDidLoad];
rootArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Addition1" ofType:#"plist"]];
currentQuestion = -1;
[self showNextQuestion];
}
-(void) showNextQuestion{
currentQuestion++;
if (currentQuestion <= 3) {
int numItems = [rootArray count];
NSMutableArray *question = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *A = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *B = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *C = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *addimage = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *Answer = [NSMutableArray arrayWithCapacity:numItems];
for (NSDictionary *itemData in rootArray) {
[question addObject:[itemData objectForKey:#"question"]];
[A addObject:[itemData objectForKey:#"A"]];
[B addObject:[itemData objectForKey:#"B"]];
[C addObject:[itemData objectForKey:#"C"]];
[addimage addObject:[itemData objectForKey:#"ImageUse"]];
[Answer addObject:[itemData objectForKey:#"ANS"]];
}
self.questionasked.text = question[currentQuestion];
self.answer1.text = A[currentQuestion];
self.answer2.text = B[currentQuestion];
self.answer3.text = C[currentQuestion];
additionImage.image = [UIImage imageNamed:addimage[currentQuestion]];
self.correctAns = Answer[currentQuestion];}
else{
NSLog(#"End of Array ");
[self performSegueWithIdentifier:#"levelpassed" sender:nil];
}
}
This area above here is where I am having the problem
When the the level is cleared C VC is having this error displaying
[CViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x71cae70
2013-03-30 21:17:31.264 thefyp[14311:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x71cae70'
I know the issue is that A is finding it hard to differentiate between segue and is trying to send C data about current question when all I want to do is display C when the A is finished showing all questions and no data is being transferred like when A is segueing to B. B & C also is a subclass of A. Any help would be appreciated
In the prepareForSegue method check the segue identifier UIStoryboardSegue.identifier whether it matches the transition to your B-VC.
Because calling performSegueWithIdentifier:#"levelPassed" will also run into this method and there you do not have a B-VC and therefore no currentQuestion.