UIView subclass is not visible - iphone

I'm a creating a subclass of UIView (MultiColumnTableView) which will hold a couple of table views. However, when I add my custom view as a subview to the view controller it is never visible, and I really can't figure out why?
I'm adding it with this code in my root view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_multiColumnTableView = [[MultiColumnTableView alloc] initWithNumberOfColums:3 columnWidth:200 frame:CGRectMake(100, 100, 0, 400)];
_multiColumnTableView.dataSource = self;
_multiColumnTableView.delegate = self;
[self.view addSubview:_multiColumnTableView];
[_multiColumnTableView reloadData];
}
The custom class initializer contains the following code:
- (id)initWithNumberOfColums:(NSInteger)columns columnWidth:(float)width frame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.numberOfColumns = columns;
self.columnWidth = columnWidth;
self.bounds = CGRectMake(0, 0, columnWidth * numberOfColumns, self.bounds.size.height);
_tableViews = [NSMutableArray new];
// Create all the desired colums (= tableViews)
for (int i = 0; i < numberOfColumns; i++) {
UITableView *t = [[UITableView alloc] initWithFrame:CGRectMake(columnWidth * i, 0, columnWidth, self.bounds.size.height)];
[_tableViews addObject:t];
t.tag = i;
t.backgroundColor = [UIColor blueColor];
t.dataSource = self;
t.delegate = self;
[self addSubview:t];
}
}
return self;
}
I'm expecting to see some blue table views, but they are not visible, and therefore they never call cellForRowAtIndexPath:, but they do call numberOfRowsInSection. My custom subview is added to the root view. When counting the subviews it returns 1. Can anyone see the problem?

check each frame of tableviews is properly assigned.

do following changes inside constructor.
- (id)initWithNumberOfColums:(NSInteger)columns columnWidth:(float)width frame:(CGRect)frame
{
self = [super initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, columns*width, frame.size.height)];
if (self) {
self.numberOfColumns = columns;
self.columnWidth = columnWidth;
_tableViews = [NSMutableArray new];
// Create all the desired colums (= tableViews)
for (int i = 0; i < numberOfColumns; i++) {
UITableView *t = [[UITableView alloc] initWithFrame:CGRectMake(columnWidth * i, 0, columnWidth, frame.size.height)];
[_tableViews addObject:t];
t.tag = i;
t.backgroundColor = [UIColor blueColor];
t.dataSource = self;
t.delegate = self;
[self addSubview:t];
}
}
return self;
}

Related

Why does my survey app make memory leak? (Multiple UIViews and UITextViews in one UIScrollView)

I am trying to make a survey app but I can't make the memory management although I am using ARC. My app makes memory leak. I get memory warning. When I make my app in interface builder statically there is no problem but when i make my app programmatically I get memory problem. Why is that happening? Here is my code:
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
int soruAdedi = 20;
#interface ViewController ()
#end
#implementation ViewController
#synthesize scrollView2;
-(void)textViewBicimle: (UITextField *)textAlani{
[textAlani.layer setBorderColor:[[[UIColor blackColor] colorWithAlphaComponent:1.0] CGColor]];
[textAlani.layer setBorderWidth:1.0];
}
- (void) tableCiz:(NSMutableArray *)hucreler sutun:(int)sutunSayisi satir:(int)satirSayisi{
int z = 0;
for (int i =0;i<satirSayisi;i++){
for(int j=0;j<sutunSayisi&&z<satirSayisi*sutunSayisi;j++,z++){
[self textViewBicimle:[hucreler objectAtIndex:z]];
[[hucreler objectAtIndex:z] setFrame:CGRectMake((20+j*100), (20+i*40), 100, 40)];
}
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
}
-(void)hucreArrayOlustur: (int)sutunSayisi suankiView:(UIView *)soruViewIki satir:(int)satirSayisi{
for (int i = 0; i <sutunSayisi*satirSayisi; i++){
textView = [[UITextField alloc]init];
textView.text = #"dsgfdh";
[hucreArray addObject:textView];
[soruViewIki addSubview:textView];
}
}
-(void)viewOlustur{
for (int i = 0; i <soruAdedi; i++){
hucreArray = [[NSMutableArray alloc]init];
if (i == 0){
soruView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 728, 0)];
soruView.clipsToBounds = YES;
soruView.backgroundColor = [UIColor lightGrayColor];
[self hucreArrayOlustur:5 suankiView:soruView satir:10];
[self tableCiz:hucreArray sutun:5 satir:10];
CGRect frame = soruView.frame;
CGRect frame2 = [[hucreArray objectAtIndex:49] frame];
frame.size.height = frame2.origin.y+frame2.size.height+34;
soruView.frame = frame;
[viewArray addObject:soruView];
[scrollView2 addSubview:soruView];
}
else{
CGRect frameGecici = [[viewArray objectAtIndex:i-1] frame];
float geciciY = frameGecici.origin.y+frameGecici.size.height+1;
soruView = [[UIView alloc]initWithFrame:CGRectMake(20, geciciY, 728, 0)];
soruView.clipsToBounds = YES;
soruView.backgroundColor = [UIColor lightGrayColor];
[self hucreArrayOlustur:5 suankiView:soruView satir:10];
[self tableCiz:hucreArray sutun:5 satir:10];
CGRect frame = soruView.frame;
CGRect frame2 = [[hucreArray objectAtIndex:49] frame];
frame.size.height = frame2.origin.y+frame2.size.height+34;
soruView.frame = frame;
[viewArray addObject:soruView];
[scrollView2 addSubview:soruView];
}
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView2.delegate = self;
scrollView2.contentSize = CGSizeMake(0, 8000);
viewArray = [[NSMutableArray alloc]init];
[self viewOlustur];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidUnload {
[self setScrollView2:nil];
[super viewDidUnload];
}
#end

Pushing ViewController with UIScrollView + UIPageControl onto specific page

I have a VC with a scrollview and pagecontrol implemented in it. It has three pages, which are all set up correctly and working fine. What I want to be able to do is have the VC load onto different pages depending on what button a user presses.
In the method the button calls I have
ViewController *vc = [[ViewController alloc] init];
vc.pageControl.currentPage = 2;
[self.navigationController pushViewController:vc animated:YES];
When the VC loads, it is loaded onto the correct page (as evidenced by the bubbles at the bottom of the page) but it is displaying the information from page[0]. If I start scrolling, it jumps back to page[0] no matter what I do.
My best guess is that I need to make the VC load to a specific x origin depending on what page I want to display, but I haven't been able to find anything related to this, so I'm quite lost.
Appreciate any help.
EDIT: Here is the code from the VC class. I didn't write this and it is my first time working with PageControl, so I'm trying to learn as I go.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.scrollView = [[UIScrollView alloc] init];
self.scrollView.pagingEnabled = TRUE;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.delegate = self;
firstPage = [[UIView alloc] init];
firstPage.tag = 0;
secondPage = [[UIView alloc] init];
secondPage.tag = 1;
thirdPage = [[UIView alloc] init];
thirdPage.tag = 2;
pages = [[NSArray alloc] initWithObjects:firstPage, secondPage, thirdPage, nil];
// Page Control
self.pageControl = [[UIPageControl alloc] init];
self.pageControl.numberOfPages = 3;
self.pageControl.currentPage = 0;
[self.view addSubview:self.scrollView];
[self.view addSubview:self.pageControl];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// First Page Setup
//
[self setupFirstPage];
// Second Page Setup
//
[self setupSecondPage];
// Third Page Setup
//
[self setupThirdPage];
// Frame everything
//
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
CGRect navBarFrame = self.navigationController.navigationBar.frame;
self.scrollView.frame = CGRectMake(0, navBarFrame.size.height, 320, screenFrame.size.height - navBarFrame.size.height);
self.pageControl.frame = CGRectMake(0, screenFrame.size.height - 70, 320, 20);
firstPage.frame = CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
secondPage.frame = CGRectMake(320 * secondPage.tag, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
thirdPage.frame = CGRectMake(320 * thirdPage.tag, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
// Add Subviews
//
[self.scrollView addSubview:firstPage];
[self.scrollView addSubview:secondPage];
[self.scrollView addSubview:thirdPage];
self.scrollView.contentSize = CGSizeMake(320 * pages.count, self.scrollView.frame.size.height);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
Try adding this function and calling it right after you set the page number:
- (void)pageSelectorChanged
{
CGRect frame = self.scrollView.frame;
frame.origin.x = frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
[self.scrollView scrollRectToVisible:frame animated:NO];
}

Error: this class is not key value coding-compliant for the key projectToolBar? [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
Hey I can't figure out an error I got. I had my App working and then I'm not sure what I did but it won't open now and instead I get this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TaskViewController 0x16c9b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key projectToolBar.'
Any Ideas what might be the problem? I can add my project code if I need to...
edit:
So i looked and in the interface builder/storyboard there was a link to projectToolBar that didn't have a corresponding line in the header file. I deleted the problem in IB, however, now I am getting a new error and it still isn't working.
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TaskViewController 0x132dd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key projectView.'
Here is my taskviewController class:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "newTaskWindow.h"
#interface TaskViewController : UIViewController <DismissPopoverDelegate>{
IBOutlet UIScrollView *taskScrollView;
AppDelegate * _appDelegate;
UIDeviceOrientation orientation;
IBOutlet UIView *newTaskView;
IBOutlet UIBarButtonItem *newTaskButton;
IBOutlet UIBarButtonItem *newTeamMemberButton;
IBOutlet UIBarButtonItem *newProjectButton;
IBOutlet UIView*taskView;
IBOutlet UIToolbar *taskToolBar;
NSMutableArray *teamMembers;
NSMutableArray *projects;
NSMutableArray *tasks;
//UIPopoverController *taskPop;
int countForX;
int countForY;
int xOffSet;
int yOffset;
int xMult;
int yMult;
int viewContentSize;
int countForTaskView;
int maxCountForX;
int maxCountForY;
int incrementForYOffset;
int viewContentSizeBase;
}
- (IBAction)newTask:(id)sender;
- (IBAction)newTeamMember:(id)sender;
- (IBAction)newProject:(id)sender;
-(void)setTasksInScreen;
#property(nonatomic, retain) AppDelegate * appDelegate;
#property (nonatomic, retain) UIPopoverController *myPopover;
#end
#protocol NewsVcDelegate <NSObject>
- (void)FirstViewController:(TaskViewController*)controller didSelectObject:(id)object;
#end
// FirstViewController.m
#import "TaskViewController.h"
#import "newTaskWindow.h"
#import "TeamMember.h"
#import "Project.h"
#import "newTeamMemberWindow.h"
#import "newProjectWindow.h"
#implementation TaskViewController
#synthesize myPopover;
#synthesize appDelegate;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
NSLog(#"Made it to TaskViewController");
self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
[self setTasksInScreen];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
//create new Team member in popover myPopover
-(IBAction)newTeamMember:(id)sender{
if ([self.myPopover isPopoverVisible]) {
//using the setters and getters "goes thru the proper channels" when accessing objects
[self.myPopover dismissPopoverAnimated:YES];
} else {
newTeamMemberWindow *teamMemberWindow = [[newTeamMemberWindow alloc]init];
[teamMemberWindow setDelegate:self];
UIPopoverController *teamMemberPop = [[UIPopoverController alloc]initWithContentViewController:teamMemberWindow];
[teamMemberPop setDelegate:self];
[teamMemberPop setPopoverContentSize:CGSizeMake(300, 450)];
//NSLog(#"Got to 6");
self.myPopover = teamMemberPop;
[self.myPopover presentPopoverFromBarButtonItem:newTeamMemberButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
//Create new Project in popover myPopover
-(IBAction)newProject:(id)sender{
if ([self.myPopover isPopoverVisible]) {
//using the setters and getters "goes thru the proper channels" when accessing objects
[self.myPopover dismissPopoverAnimated:YES];
} else {
newProjectWindow *projectWindow = [[newProjectWindow alloc]init];
[projectWindow setDelegate:self];
UIPopoverController *projectPop = [[UIPopoverController alloc]initWithContentViewController:projectWindow];
[projectPop setDelegate:self];
[projectPop setPopoverContentSize:CGSizeMake(300, 450)];
self.myPopover = projectPop;
[self.myPopover presentPopoverFromBarButtonItem:newProjectButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
//Create new Task in popover myPopover
-(IBAction)newTask:(id)sender{
if ([self.myPopover isPopoverVisible])
{
[self.myPopover dismissPopoverAnimated:YES];
} else {
NSString* test1 = [[NSString alloc]initWithFormat:#"Robby"];
[teamMembers addObject:test1];
newTaskWindow *newTaskWin = [[newTaskWindow alloc]init];
[newTaskWin setDelegate:self];
UIView *test = [[UIView alloc]init];
[newTaskWin setTeamMembers:teamMembers];
test = newTaskWin.view;
UIPopoverController *taskPop = [[UIPopoverController alloc]initWithContentViewController:newTaskWin];
[taskPop setDelegate:self];
[taskPop setPopoverContentSize:CGSizeMake(300, 450)];
self.myPopover = taskPop;
[self.myPopover presentPopoverFromBarButtonItem:newTaskButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
-(void)setTasksInScreen{
//remove all views that were in The task view. If you don't do this, a new view is placed on top everytime you call setTasksInScreen method and the buttons begin to overlap.
for (UIView *view in [taskView subviews]) {
[view removeFromSuperview];
}
//The placement of the buttons is different depending on which orientation we are in. We handle this with an if statement
if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
countForX = 0;
countForY = 0;
xOffSet = 27;
yOffset = 60;
maxCountForX = 3;
maxCountForY = 4;
incrementForYOffset = 911;
xMult = 250;
yMult = 210;
viewContentSize = 0;
countForTaskView = 1;
viewContentSizeBase = 911;
NSLog(#"Portrait view");
}
else{
countForX = 0;
countForY = 0;
maxCountForX = 4;
maxCountForY = 3;
incrementForYOffset = 654;
xOffSet = 41;
yOffset = 50;
xMult = 240;
yMult = 200;
viewContentSize = 0;
countForTaskView = 1;
viewContentSizeBase = 654;
NSLog(#"LandScape view");
}
//Create Scrollview to be able to scroll through the different tasks
taskScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height -45)];
tasks = [[NSMutableArray alloc] initWithArray:self.appDelegate.tasks];
Task *tempTask = [[Task alloc]init];
for(int i =0; i < [tasks count]; i++){
tempTask = [tasks objectAtIndex:i];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//Set the style that you want the date to be here (ie. MM-DD-YYYY ect)
[formatter setDateStyle:NSDateFormatterFullStyle];
NSDate *endDateForButton = [tempTask endDate];
//Use custom Button so that you can add in background pic
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xOffSet+(countForX*xMult), yOffset +(countForY*yMult), 215, 156);
UIImage *buttonBackground = [UIImage imageNamed:#"rectangleImage.png"];
[button setBackgroundImage:buttonBackground forState:UIControlStateNormal];
//add labels to button for information
UILabel *taskName = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 200, 45)];
taskName.text = [tempTask taskName];
[taskName setTextAlignment:UITextAlignmentCenter];
[button addSubview:taskName];
//Label that says "Due on"
UILabel *dueLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, 200, 45)];
dueLabel.text = #"Due on";
[dueLabel setTextAlignment:UITextAlignmentCenter];
[button addSubview:dueLabel];
UILabel *endDate = [[UILabel alloc]initWithFrame:CGRectMake(5, 80, 200, 45)];
endDate.text = [formatter stringFromDate:[tempTask endDate]];
[endDate setTextAlignment:UITextAlignmentCenter];
[button addSubview:endDate];
countForX++;
if(countForX >= maxCountForX)
{
countForY++;
countForX = 0;
}
if(countForY >=maxCountForY)
{
countForY = 0;
countForX = 0;
yOffset +=incrementForYOffset;
countForTaskView++;
}
[taskScrollView addSubview:button];
}//for loop
[taskView addSubview:taskScrollView];
[taskView bringSubviewToFront:taskToolBar];
//[taskScrollView addSubview:viewForTaskScrollView];
viewContentSize = viewContentSizeBase * (countForTaskView);
taskScrollView.contentSize = CGSizeMake(taskView.frame.size.width, viewContentSize);
[taskScrollView setPagingEnabled:YES];
}
-(void)setProjectsInScreen{
//remove all views that were in The task view. If you don't do this, a new view is placed on top everytime you call setTasksInScreen method and the buttons begin to overlap.
for (UIView *view in [taskView subviews]) {
[view removeFromSuperview];
}
//The placement of the buttons is different depending on which orientation we are in. We handle this with an if statement
if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
countForX = 0;
countForY = 0;
xOffSet = 27;
yOffset = 60;
maxCountForX = 3;
maxCountForY = 4;
incrementForYOffset = 911;
xMult = 250;
yMult = 210;
viewContentSize = 0;
countForTaskView = 1;
viewContentSizeBase = 911;
NSLog(#"Portrait view");
}
else{
countForX = 0;
countForY = 0;
maxCountForX = 4;
maxCountForY = 3;
incrementForYOffset = 654;
xOffSet = 41;
yOffset = 50;
xMult = 240;
yMult = 200;
viewContentSize = 0;
countForTaskView = 1;
viewContentSizeBase = 654;
NSLog(#"LandScape view");
}
//Create Scrollview to be able to scroll through the different tasks
taskScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height -45)];
projects = [[NSMutableArray alloc] initWithArray:self.appDelegate.projects];
Project *tempProject = [[Project alloc]init];
for(int i =0; i < [tasks count]; i++){
tempProject = [tasks objectAtIndex:i];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xOffSet+(countForX*xMult), yOffset +(countForY*yMult), 215, 156);
UIImage *buttonBackground = [UIImage imageNamed:#"rectangleImage.png"];
[button setBackgroundImage:buttonBackground forState:UIControlStateNormal];
//add labels to button for information
UILabel *projectName = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 200, 45)];
projectName.text = [tempProject projectName];
[projectName setTextAlignment:UITextAlignmentCenter];
[button addSubview:projectName];
//Label that says "Due on"
UILabel *dueLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, 200, 45)];
dueLabel.text = #"Due on";
[dueLabel setTextAlignment:UITextAlignmentCenter];
[button addSubview:dueLabel];
countForX++;
if(countForX >= maxCountForX)
{
countForY++;
countForX = 0;
}
if(countForY >=maxCountForY)
{
countForY = 0;
countForX = 0;
yOffset +=incrementForYOffset;
countForTaskView++;
}
[taskScrollView addSubview:button];
}//for loop
[taskView addSubview:taskScrollView];
[taskView bringSubviewToFront:taskToolBar];
//[taskScrollView addSubview:viewForTaskScrollView];
viewContentSize = viewContentSizeBase * (countForTaskView);
taskScrollView.contentSize = CGSizeMake(taskView.frame.size.width, viewContentSize);
[taskScrollView setPagingEnabled:YES];
}
-(void)setTeamMembersInScreen{
//remove all views that were in The task view. If you don't do this, a new view is placed on top everytime you call setTasksInScreen method and the buttons begin to overlap.
for (UIView *view in [taskView subviews]) {
[view removeFromSuperview];
}
//The placement of the buttons is different depending on which orientation we are in. We handle this with an if statement
if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
countForX = 0;
countForY = 0;
xOffSet = 27;
yOffset = 60;
maxCountForX = 3;
maxCountForY = 4;
incrementForYOffset = 911;
xMult = 250;
yMult = 210;
viewContentSize = 0;
countForTaskView = 1;
viewContentSizeBase = 911;
NSLog(#"Portrait view");
}
else{
countForX = 0;
countForY = 0;
maxCountForX = 4;
maxCountForY = 3;
incrementForYOffset = 654;
xOffSet = 41;
yOffset = 50;
xMult = 240;
yMult = 200;
viewContentSize = 0;
countForTaskView = 1;
viewContentSizeBase = 654;
NSLog(#"LandScape view");
}
//Create Scrollview to be able to scroll through the different tasks
taskScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height -45)];
tasks = [[NSMutableArray alloc] initWithArray:self.appDelegate.tasks];
Task *tempTask = [[Task alloc]init];
for(int i =0; i < [tasks count]; i++){
tempTask = [tasks objectAtIndex:i];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//Set the style that you want the date to be here (ie. MM-DD-YYYY ect)
[formatter setDateStyle:NSDateFormatterFullStyle];
NSDate *endDateForButton = [tempTask endDate];
//Use custom Button so that you can add in background pic
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xOffSet+(countForX*xMult), yOffset +(countForY*yMult), 215, 156);
UIImage *buttonBackground = [UIImage imageNamed:#"rectangleImage.png"];
[button setBackgroundImage:buttonBackground forState:UIControlStateNormal];
//add labels to button for information
UILabel *taskName = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 200, 45)];
taskName.text = [tempTask taskName];
[taskName setTextAlignment:UITextAlignmentCenter];
[button addSubview:taskName];
//Label that says "Due on"
UILabel *dueLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, 200, 45)];
dueLabel.text = #"Due on";
[dueLabel setTextAlignment:UITextAlignmentCenter];
[button addSubview:dueLabel];
UILabel *endDate = [[UILabel alloc]initWithFrame:CGRectMake(5, 80, 200, 45)];
endDate.text = [formatter stringFromDate:[tempTask endDate]];
[endDate setTextAlignment:UITextAlignmentCenter];
[button addSubview:endDate];
countForX++;
if(countForX >= maxCountForX)
{
countForY++;
countForX = 0;
}
if(countForY >=maxCountForY)
{
countForY = 0;
countForX = 0;
yOffset +=incrementForYOffset;
countForTaskView++;
}
[taskScrollView addSubview:button];
}//for loop
[taskView addSubview:taskScrollView];
[taskView bringSubviewToFront:taskToolBar];
//[taskScrollView addSubview:viewForTaskScrollView];
viewContentSize = viewContentSizeBase * (countForTaskView);
taskScrollView.contentSize = CGSizeMake(taskView.frame.size.width, viewContentSize);
[taskScrollView setPagingEnabled:YES];
}
- (void) dismissPopover:(NSString *)data
{ /* Dismiss you popover here and process data */
[self.myPopover dismissPopoverAnimated:YES];
[self setTasksInScreen];
//[myPopover dismissPopoverAnimated:YES];
}
// Some method, when you create popover
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
return YES;
}
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
- (void)deviceOrientationDidChange:(NSNotification *)notification {
[self setTasksInScreen];
}
#end
Most likely you have a xib file that houses a toolBar that is still connected to a (now nonexistent) outlet named projectToolBar.
You removed IBOutlet UIToolBar *projectToolBar; from your TaskViewController.h file.
You should think about using source control management, so you can see what you did. ;-)
Xcode 4 Guide - Managing Versions of Your Project
I'm betting you're trying to fill your TaskViewController using setValuesForKeysWithDictionary: or something like that, and projectToolBar isn't a valid #property in your view controller's header file.
It could also be what #MatthiasBauch said.
I had the same error after adding a few objects to a UITableViewCell on storyboard. Before that, the app was working perfectly.
I was able to resolve this issue by going Xcode > Preferences > Locations > Derived Data, ,opened the directory and deleted the folders with the app's name.
Hope my comment will be helpful for those come here later.

Adding multiple navigation controllers inside a view controller?

I'm trying to acheive a dual-tabBar app for the iPhone and using the following code for a base class view controller to add several navigation controllers inside the view controller (see code below). But the problem is: No subviews are added to self.view, despite them being initialized earlier. Any ideas?
- (IBAction)ViewButtonPressed:(id)sender
{
UIButton *b = (UIButton *)sender;
int index = b.tag - 1000;
[self SelectNavigationController:index];
}
- (void)SelectNavigationController:(int)index
{
// Set index to top-most view ->
UINavigationController *nc = (UINavigationController *)[navigationControllers objectAtIndex:index];
[self.view bringSubviewToFront:nc.view];
}
#pragma mark -
#pragma mark display
- (void)Display
{
CGRect frame = CGRectMake(0, 44, 320, 367);
// Create buttons above frame and show navigation controller inside frame ->
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.origin.y)];
for (int i=0; i<[navigationControllers count]; ++i)
{
UINavigationController *nc = (UINavigationController *)[navigationControllers objectAtIndex:i];
UIViewController *vc = [nc.viewControllers objectAtIndex:0];
NSString *titel = vc.navigationItem.title;
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setBackgroundColor:[UIColor lightGrayColor]]; // TODO: Replace with image <-
[b setTitle:titel forState:UIControlStateNormal];
b.tag = i + 1000;
[b setFrame:CGRectMake(i * frame.size.width / 3, 0, frame.size.width / 3, frame.origin.y - 1)];
[v addSubview:b];
}
for (int j=0; j<[navigationControllers count]; ++j)
{
UINavigationController *nc = (UINavigationController *)[navigationControllers objectAtIndex:j];
[nc.navigationBar addSubview:v];
[self.view addSubview:nc.view]; // Add view to view <-
nc.view.frame = frame;
}
[v release];
if (VIEW_DEBUG)
NSLog(#"BaseTabViewController.m: self.view.subviews: %d", [self.view.subviews count]);
}
#pragma mark -
#pragma mark addviewcontroller
- (void)AddViewControllerForNavigationController:(UIViewController *)viewController
{
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.view.backgroundColor = [UIColor greenColor];
[navigationControllers addObject:navController];
[navController release];
}
#pragma mark -
#pragma mark init, loadView, viewDidLoad and dealloc
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder])
{
navigationControllers = [[NSMutableArray alloc] init];
}
return self;
}
- (void)loadView
{
//
}
- (void)viewDidLoad
{
if (!viewDidLoadAlready)
{
[self Display];
viewDidLoadAlready = YES;
[super viewDidLoad];
}
}
And the code in the subclass:
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder])
{
PistKartaViewController *pistKarta = [[PistKartaViewController alloc] init];
pistKarta.navigationItem.title = #"Pistkarta";
LiftRapportViewController *liftRapport = [[LiftRapportViewController alloc] init];
liftRapport.navigationItem.title = #"Liftrapport";
SkipassViewController *skiPass = [[SkipassViewController alloc] init];
skiPass.navigationItem.title = #"Skipass";
[self AddViewControllerForNavigationController:pistKarta];
[self AddViewControllerForNavigationController:liftRapport];
[self AddViewControllerForNavigationController:skiPass];
[pistKarta release];
[liftRapport release];
[skiPass release];
}
return self;
}
I figured it out. I had the following in a view controller I was adding...
- (void)loadView
{
}
, which of course means that the superclass won't be loaded at all. Stupid. Otherwise, this method works quite well. :)

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.