NSNSInternalInconsistencyException, Missing outlet IOS7 - iphone

Okay, I am stumped... all the answers related missing outlets point to making sure that the outlet is connected. I have made sure that it is. You can see it in the screenshots below. The problem is that the code runs in IOS5.0. So this is definitely some compatibility related issue. I have also tried what was suggested in the two answers. But that doesn't help.
Here is the code that invokes the xib. Any clues? Thank you for helping.
- (id) initWithModuleDataDict:(id)dataObject andStepNumber:(int)stepNumber
{
if ((self = [super initWithNibName:#"PhoneContent" bundle:nil])) {
self.moduleData = (NSDictionary *)dataObject;
self.module = [self.moduleData objectForKey:kModuleClassKey];
numberOfSteps = [[self.module steps] count];
self.doShowMeasurementViews = self.module.doShowMeasurementViews;
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
// view controllers are created lazily in the loadScrollViewWithPage: method...
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < numberOfSteps; i++)
{
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
// CGRect fullScreenRect = [[UIScreen mainScreen] applicationFrame];
CGRect fullScreenRect = CGRectMake(0, 0, 320, 372);
UIScrollView *theScrollView = [[UIScrollView alloc] initWithFrame:fullScreenRect];
self.scrollView = theScrollView;
[theScrollView release];
CGRect bottomRect = CGRectMake(0, 410, 320, 20);
UIPageControl *thePageControl = [[UIPageControl alloc] initWithFrame:bottomRect];
thePageControl.center = CGPointMake(160.0, 400.0);
self.pageControl = thePageControl;
[thePageControl release];
// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * numberOfSteps, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
scrollView.decelerationRate = UIScrollViewDecelerationRateFast; //shp
pageControl.numberOfPages = numberOfSteps;
pageControl.currentPage = stepNumber;
// Create the transition sound
// Create the url for the source audio file (URLForResource:withExtension: method is new in 4.0)
NSURL *purrSound = [[NSBundle mainBundle]URLForResource:#"purr"
withExtension:#"aiff"];
// Store the url as a CFURLRef instance
self.soundFileURLRef = (CFURLRef)[purrSound retain];
// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);
[controllers release];
}
return self;
}

I have had mixed experiences porting and upgrading old xibs to the new Xcode.
What I have done in these instances is just make a new xib file and copy and paste the controls over from the old. Then I re-assign the superclass and remap the delegates.
I wish I had a better solution, but this has worked for me.
Also, if you were not using AutoLayout in the previous XCode project, keep an eye out for that in Xcode 5 its a little different.

Please add this logic in your code.
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
And read this doc carefully.

Related

Adding an UIView programmatically not working (UIView should show an UIWebView and open URL)

Currently working on two introduction pages (First shows an image, second should show a website) for my iPhone app (like Pocket, for the user a little hands-on after first start).
Came across Matthew York's GitHub project which works perfectly with images and text.
Additionally I like to show a website as a part of the introduction but I can't get it working. My programmatically created UIWebView just doesn't show up.
Matthew York's GitHub Project:
https://github.com/MatthewYork/iPhone-IntroductionTutorial
Complete code for showing the two introduction pages is shown below.
Please mind that panelImage works as expected but not panelView.
I see the second page show up but without the UIWebView.
I think I add the subview to a view not visible on the screen therefore I don't see it. Am I right? Can you please have a look at: [view addSubview:aWebView]; in method: showWebView
ViewController.m
- (void)showIntro
{
MYIntroductionPanel *panelImage = [[MYIntroductionPanel alloc] initWithimage:[UIImage imageNamed:#"img.jpg"] description:#"TEST: IMAGE"];
MYIntroductionPanel *panelView = [[MYIntroductionPanel alloc] initWitView:[self showWebView] description:#"TEST: VIEW"];
MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) headerText:#"TESTING" panels:#[panelImage, panelView] languageDirection:MYLanguageDirectionLeftToRight];
introductionView.BackgroundImageView.image = [UIImage imageNamed:#"BG_iPad_1024.png"];
introductionView.delegate = self;
[introductionView showInView:self.view];
}
- (UIView *)showWebView
{
UIWebView *aWebView= [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 290)];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]];
[aWebView loadRequest:requestObj];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
[view addSubview:aWebView];
return view;
}
MYIntroductionPanel.m
-(id)initWitView:(UIView *)view description:(NSString *)description{
if (self = [super init]) {
self.view = [[UIView alloc] init];
self.Description = [[NSString alloc] initWithString:description];
}
return self;
}
-(id)initWithimage:(UIImage *)image title:(NSString *)title description:(NSString *)description{
if (self = [super init]) {
self.Image = [[UIImage alloc] init];
self.Image = image;
self.Title = title;
self.Description = [[NSString alloc] initWithString:description];
}
return self;
}
The view to which you are adding your UIWebView is never added to the view hierarchy itself. You appear to be passing the UIWebView's superview to MyIntroductionPanel's initWithView:description: method, but that method just ignores its input view and creates a new one with self.view = [[UIView alloc] init]. Try setting self.view = view in your initWithView:description: method instead.
I didn't love all of the author's decisions, but followed his pattern to achieve what you're looking for.
Added the following:
// MyIntroductionPanel.h
#property (nonatomic, retain) NSURL *url;
-(id)initWithURL:(NSURL *)url;
// MyIntroductionPanel.m
-(id)initWithURL:(NSURL *)url {
if (self = [super init]) {
_url = url;
}
return self;
}
That was easy. This was less easy - hacking the layout method to deal with panels with urls. I didn't try too hard to understand this method, just added what I could to get it working. My additions are marked with // DANH
// MYIntroductionView.m
-(UIView *)PanelViewForPanel:(MYIntroductionPanel *)panel atXIndex:(CGFloat*)xIndex{
// snipped original code
NSInteger descriptionHeight = panelDescriptionTextView.contentSize.height;
int contentWrappedScrollViewHeight = 0;
if ((imageHeight + descriptionHeight + panelTitleLabelFrame.size.height) > maxScrollViewHeight) {
contentWrappedScrollViewHeight = maxScrollViewHeight;
imageHeight = contentWrappedScrollViewHeight-descriptionHeight - panelTitleLabelFrame.size.height - 10;
}
else if ((imageHeight+descriptionHeight + panelTitleLabelFrame.size.height) <= maxScrollViewHeight){
contentWrappedScrollViewHeight = imageHeight + panelTitleLabelFrame.size.height + descriptionHeight;
}
// DANH
if (panel.url) {
contentWrappedScrollViewHeight = 300;
// you can certainly do a better job than I did here, but just to get going
}
panelView.frame = CGRectMake(*xIndex, 0, self.ContentScrollView.frame.size.width, contentWrappedScrollViewHeight);
//Build image container
UIImageView *panelImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 0, self.ContentScrollView.frame.size.width - 10, imageHeight)];
panelImageView.contentMode = UIViewContentModeScaleAspectFit;
panelImageView.backgroundColor = [UIColor clearColor];
panelImageView.image = panel.Image;
panelImageView.layer.cornerRadius = 3;
panelImageView.clipsToBounds = YES;
[panelView addSubview:panelImageView];
// DANH
// add webview on top if we have a url
if (panel.url) {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.ContentScrollView.frame.size.width, 300)];
[webView loadRequest:[NSURLRequest requestWithURL:panel.url]];
[panelView addSubview:webView];
}
// snipped original code
}
Now, to call it with example code....
// MYViewController.m
MYIntroductionPanel *panel3 = [[MYIntroductionPanel alloc] initWithURL:[NSURL URLWithString:#"http://www.google.com"]];
// ...
MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) headerText:#"MYIntroductionView" panels:#[panel, panel2, panel3] languageDirection:MYLanguageDirectionLeftToRight];

How Do I Switch Views With PageControl & UIScrollView?

I'm a noob to Iphone development (3rd day in Xcode) and I am trying to implement pageControl and scrollview so users can swipe between various pages. I'm using this tutorial and I can't figure out how to load/switch views from nib files as opposed to just changing the background color of a view. Any help is greatly appreciated.
MY CODE
Modification of PageControlExampleViewController.m renamed NewsClass2
// Creates the color list the first time this method is invoked. Returns one color object from the list.
+ (UIColor *)pageControlColorWithIndex:(NSUInteger)index {
if (__pageControlColorList == nil) {
__pageControlColorList = [[NSArray alloc] initWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor magentaColor],
[UIColor blueColor], [UIColor orangeColor], [UIColor brownColor], [UIColor grayColor], nil];
}
// Mod the index by the list length to ensure access remains in bounds.
return [__pageControlColorList objectAtIndex:index % [__pageControlColorList count]];
}
//Changing views instead of colors, not working
+ (UIView *)pageControlViewWithIndex:(NSUInteger)index {
if (__pageControlViewrList == nil) {
__pageControlViewrList = [[NSArray alloc] initWithObjects:[[UIView alloc] initWithNibName:#"PageView" bundle:nil], [[UIView alloc] initWithNibName:#"PageView" bundle:nil], [[UIView alloc] initWithNibName:#"PageView" bundle:nil],
[[UIView alloc] initWithNibName:#"PageView" bundle:nil], [[UIView alloc] initWithNibName:#"PageView" bundle:nil], [[UIView alloc] initWithNibName:#"PageView" bundle:nil], [[UIView alloc] initWithNibName:#"PageView" bundle:nil], nil];
}
// Mod the index by the list length to ensure access remains in bounds.
return [__pageControlViewList objectAtIndex:index % [__pageControlViewList count]];
}
// Set the label and background color when the view has finished loading.
- (void)viewDidLoad {
pageNumberLabel.text = [NSString stringWithFormat:#"Page %d", pageNumber + 1];
self.view.backgroundColor = [NewsClass2 pageControlColorWithIndex:pageNumber];
//Setting View Not Working
self.view = [NewsClass2 pageControlViewWithIndex:pageNumber];
}
welcome to Objective C.
First of all you need to set delegate of scroll view like
//in .h file write
#interface ViewController : UIViewController<UIScrollViewDelegate>
// in viewDidLoad
self.scrollView.delegate = self;
then write in delegate method of UIScrollView write...
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
then make an IBAction of valueChange for pageControl like .....
- (IBAction)changePage:(id)sender
{
int page = self.pageControlHelp.currentPage;
CGRect frame = self.scrollViewHelp.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[self.scrollViewHelp scrollRectToVisible:frame animated:YES];
}
And you have done .......
If you have any confusion for this please feel free to ask......

Display A TTStyledTextLabel in a UITableView

How can I set a TTStyledTextLabel inside of a UITableView.
Each TTStyledTextLabel contains Some parsed HTML.
Heres what I have I realize its probably completely wrong.
TTStyledTextLabel* label = [[TTStyledTextLabel alloc] autorelease];
cell.textLabel.text = [TTStyledText textFromXHTML:tempString lineBreaks:YES URLs:YES];
App Crashes on launch. I think its because I am setting the .text property with something that is not text. However, I don't know what else to set.
The following code will do what you want. Unfortunately, however, I cannot figure out how to automatically set the height. If memory isn't an issue you could keep a seperate array of TTStyledTextLabels and reference their heights.
in your loadView:
CGRect cgRct2 = CGRectMake(0, 35, 320, 375); //define size and position of view
tblView = [[UITableView alloc] initWithFrame:cgRct2 style:UITableViewStylePlain];
tblView.dataSource = [self constructDataSource];
tblView.delegate = self;
//[tblView reloadData];
[myView addSubview:tblView];
in your class:
-(TTListDataSource *)constructDataSource {
NSLog(#"constructDataSource");
NSMutableArray * namesArray = [[NSMutableArray alloc] init];
//ADD ITEMS
[namesArray addObject:[TTStyledText textFromXHTML:[NSString stringWithString:#"some XHTML"]]];
TTListDataSource * dataSource = [[TTListDataSource alloc] init];
for (int i = 0; i < [namesArray count]; i++) {
TTStyledText * text = [namesArray objectAtIndex:i];
[dataSource.items addObject:[TTTableStyledTextItem itemWithText:text]];
}
[namesArray release];
return dataSource;
}

Issue while implementing MVC

I am facing an issue while implementing MVC. I created a UIView subclass and have designed my custom view. I created a UIViewController subclass and pointed its view to my custom view class. Finally I created a NSObject subclass and created a model for my controller. When i am running the app, i am getting a black screen... Any idea on this?
==My Model==
- (id) init
{
imgArray = [[NSMutableArray alloc] initWithObjects: [UIImage imageNamed:#"scene.jpg"],
[UIImage imageNamed:#"scene1.jpg"],
[UIImage imageNamed:#"scene2.jpg"], nil];
return self;
}
==My Controller==
- (void)viewDidLoad {
[super viewDidLoad];
NSNotification
CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];
// Get the view
MVCView *myView = [[MVCView alloc] initWithFrame:mainFrame];
// Get the data
MVCModel *myModel = [[MVCModel alloc] init];
myView.myImgView.image = [myModel.imgArray objectAtIndex:0];
//[self.view addSubview:myView];
[myView setNeedsDisplay];
self.view = myView;
self.title = #"MVC";
}
==My View==
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
CGRect imgFrame = CGRectMake(5, 20, 150, 150);
//myImgView.image = [UIImage imageNamed:#"scene.jpg"];
myImgView.frame = imgFrame;
CGRect lblFrame = CGRectMake(5, 150, 50, 50);
myLabel.text = #"Nature is beautiful";
myLabel.frame = lblFrame;
CGRect sldFrame = CGRectMake(5, 200, 50, 50);
mySlider.minimumValue = 0;
mySlider.maximumValue = 100;
mySlider.frame = sldFrame;
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGPoint imgPoint = CGPointMake(10, 20);
[self.myImgView drawAtPoint:imgPoint];
CGPoint lblPoint = CGPointMake(10, 160);
[self.myLabel drawAtPoint:lblPoint];
CGPoint sldPoint = CGPointMake(10, 210);
[self.mySlider drawAtPoint:sldPoint];
}
Have you set your UIViewController's view as a subview of the Window's view that comes with your AppDelegate in your application:didFinishLaunchingWithOptions:?
I got the issue... Actually, i was not allocating memory to my UIView subclass components and was trying to use drawAtPoint method. Once i allocated memory to and added them as a subview of my view class, i got the correct screen displayed.

Add PageControl programmatically

I would like to add a UIPageControl item programmatically to my view Controller. The self.view property contains a UIScrollView with the following properties:
scrollView = [[UIScrollView alloc] initWithFrame:applicationFrame];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.maximumZoomScale = 1.0;
scrollView.minimumZoomScale = 1.0;
scrollView.clipsToBounds = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
self.view = scrollView;
So far so good. Now I wanted to add a PageControl element by adding this (a few lines later):
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
The pageControl element is synthesized using the #property and #synthesize. However, this does not display anything, even if I add a [self.view addSubview:pageControl];
Any ideas why this is not working?
Thanks to the comment from Nimrod I had the right idea, here is how it worked (rather obvious now that my version failed :))
// Init Page Control
pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(x, y, xx, yy);
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];