Solved

Connect picker view to my second View in interface builder (XCode)

Posted on 2010-11-09
1
1,893 Views
Last Modified: 2012-05-10
I have an Xcode project where I'm having two different views. On my second view I want to change some settings. Therefore I added a picker view (you know the wheel where values can be selected). I have tried to connect a picker to an application with a single view. Thats no problem at all.

I created these two connections:

A connection from the dataSource to the File's owner
A connection from the delegate to the File's owner.


When I try to connect the picker the same way in the second view of an application with two views it doesn't work with the dataSource set to Files owner. If I connect this way the application simply will not start.

How should I connect the dataSource of my picker in the second view in interface builder to be able to see the data in the picker?

I'm almost certain that the connection is the problem.

I attached code from the Filtering class (both .h and .m file). This class should be used to add data to the picker but it does not work. I also added a screenshot of how the structure is in Interface builder.

I really hope you can help me.
#import "Filtrering.h"



@implementation Filtrering



- (void)viewDidLoad { // When the view loads, run this action.

	[super viewDidLoad]; // This NEEDS to be here or the application will not work!

	

	

	pickerViewArray = [[NSMutableArray alloc] init]; // This will allocate tableViewArray.

	for(int i = 1; i <= 20; i ++) { // Set 'i' to every number from 1 and 20.

		NSString *myString = [NSString stringWithFormat:@"%d%%", i]; // Create a new string that will display the number 'i' followed by a percent sign.

		[pickerViewArray addObject:myString]; // Add the string to the tableViewArray. 

	}

}



- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { // This method needs to be used. It asks how many columns will be used in the UIPickerView

	return 1; // We only need one column so we will return 1.

}



- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { // This method also needs to be used. This asks how many rows the UIPickerView will have.

	return [pickerViewArray count]; // We will need the amount of rows that we used in the pickerViewArray, so we will return the count of the array.

}



- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { // This method asks for what the title or label of each row will be.

	return [pickerViewArray objectAtIndex:row]; // We will set a new row for every string used in the array.

}



@end

Open in new window

#import <UIKit/UIKit.h>

#import <Foundation/Foundation.h>



@interface Filtrering : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>

{

	IBOutlet UIPickerView * tipPicker;

	NSMutableArray * pickerViewArray;

}



@end

Open in new window

interface-builder.jpg
0
Comment
Question by:154115
1 Comment
 

Accepted Solution

by:
154115 earned 0 total points
ID: 34115165
I found out myself. It was because I didn't use the main class in my project. Now it works perfectly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now