Encapsulation when moving from xib to storyboards? - iphone

With xibs, you could call different initializers:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Fetch Note...
// Initialize Edit Note View Controller with the fetched Note
EditNoteViewController *vc = [[EditNoteViewController alloc] initWithNote:note];
// Push View Controller onto Navigation Stack
[self.navigationController pushViewController:vc animated:YES];
}
This allowed me to keep my variables (in the EditNoteViewController) private and I was also able to set default values to some of the variables, e.g.
- (id)initWithNote:(Note *)note {
// ....
if (self) {
self.note = note;
self.isEditing = YES;
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
//...
if (self) {
self.isEditing = NO;
}
return self;
}
I'm now trying to work with storyboards:
is there a good way to set variables from prepareForSegue without exposing variables or any other implementation?
how can I set default values?
Please be as explicit as possible

You can use - initWithCoder:
This method is called whether you instantiate a UIViewController from nibs or storyboards.
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self) {
// initializations here
}
return self;
}

You should user prepareForSegue. Expose only what you need to in the receiving View Controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Prepare for next view controller
if ([segue.identifier isEqualToString:#"someThing"]) {
SomeThingViewController *viewController = segue.destinationViewController;
viewController.someProperty = #"something else";
}
}
The property someProperty would need to be exposed in the header for SomeThingViewController
#property (nonatomic, strong) NSString *someProperty;
To set a default value, check the value of the property in viewDidLoad of the receiving view controller
if (someProperty==nil) someProperty = #"Default";

Related

iOS - Passing variable to view controller

I have a view with a view controller and when I show this view on screen, I want to be able to pass variables to it from the calling class, so that I can set the values of labels etc.
First, I just tried creating a property for one of the labels, and calling that from the calling class. For example:
SetTeamsViewController *vc = [[SetTeamsViewController alloc] init];
vc.myLabel.text = self.teamCount;
[self presentModalViewController:vc animated:YES];
[vc release];
However, this didn't work. So I tried creating a convenience initializer.
SetTeamsViewController *vc = [[SetTeamsViewController alloc] initWithTeamCount:self.teamCount];
And then in the SetTeamsViewController I had
- (id)initWithTeamCount:(int)teamCount {
self = [super initWithNibName:nil bundle:nil];
if (self) {
// Custom initialization
self.teamCountLabel.text = [NSString stringWithFormat:#"%d",teamCount];
}
return self;
}
However, this didn't work either. It's just loading whatever value I've given the label in the nib file. I've littered the code with NSLog()s and it is passing the correct variable values around, it's just not setting the label.
Any help would be greatly appreciated.
EDIT: I've just tried setting an instance variable in my designated initializer, and then setting the label in viewDidLoad and that works! Is this the best way to do this?
Also, when dismissing this modal view controller, I update the text of a button in the view of the calling ViewController too. However, if I press this button again (to show the modal view again) whilst the other view is animating on screen, the button temporarily has it's original value again (from the nib). Does anyone know why this is?
When a view controller is being initialized, inside the initWithNibName method, the views that reside in the view controller aren't yet initialized and you can't set their properties yet. Do whatever you need that is view based in the "viewDidLoad" method.
I am not a pro but this may help you.
In the header view1.h, declare the desired property:
// view1.h
#interface view1 : UIViewController {
NSString *passingVariable;
}
#property (nonatomic, strong) NSString *passingVariable;
#end
and then in the implementation of view1, synthesize the variable:
// view1.m
#implementation view1
#synthesize passingVariable;
// the rest of the implementation
#end
and, finally in the implementation of the other view controller, view2:
// view2.m
#import "view1.h"
#implementation view2
-(IBAction)changeview
{
view1 *myview = [[view1 alloc] init];
myview.passingVariable = #"Hello Variable";
[self.navigationController pushViewController:myview animated:YES];
}
#end
here i am trying to move from view2 to view 1 and also initializing the passingVariable ivar of view1. hope this will help you.
Here i'm passing the ViewController's label text to SecondViewController's Label Text
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
// please make your control on XIB set these IBOutlet's
//I'm not showing how to connect these with XIB
IBOutlet UILabel *lblView;
IBOutlet UIButton *buttonGo;
}
//this is method which will push the view
-(IBAction)buttonGoClickAction:(id)sender;
ViewController.m
-(IBAction)buttonGoClickAction:(id)sender
{
SecondViewController *secondViewObject = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
//before pushing give the text
secondViewObject.string = lblView.text;
[self.navigationController pushViewController:secondViewObject animated:YES];
}
SecondViewController.h
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController
{
IBOutlet UILabel *labelView;
NSString *string;
}
//set the string property
#property(nonatomic, retain) NSString *string;
#end
SecondViewController.m
#import "SecondViewController.h"
#implementation SecondViewController
//synthesize string here
#synthesize string;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//Here you will get the string
labelView.text = string;
}
Firstly you check that have you attach this label IBOutlet in xib or not if you made it via Interface Builder....
use it like this....
SetTeamsViewController *vc = [[SetTeamsViewController alloc] initWithTeamCount:teamCount];
Take a string variable in .h file and set that string here .. NSSting *str in .h
- (id)initWithTeamCount:(int)teamCount {
self = [super init];
if (self) {
// Custom initialization
str = [NSString stringWithFormat:#"%d",teamCount];
}
return self;
}
and set your label in viewDidLoad: or in viewWillApear:
self.teamCountLabel.text = str;
May this will help you
As said by stavash, control in the xib are created in the view did load. To be more precise, they are created with that line :
[super viewDidLoad];
So, mylabel doesn't exist before that time (it is nil).
The easiest way is to do that :
SetTeamsViewController *vc = [[SetTeamsViewController alloc] init];
[self presentModalViewController:vc animated:YES];
vc.myLabel.text = self.teamCount;
[vc release];
The longer but more correct path is to have a member NSString* in SetTeamsViewController class, to set it to teamCount before showing the window, and in the view did load to put that membre value in your label.
Cdt
It depends on your need. You can use Singleton class for sharing of your variables between different classes. Define all variable which you wants share in your DataClass.
in .h file (where RootViewController is my DataClass, replace name with your new class)
+(RootViewController*)sharedFirstViewController;
in .m file
//make the class singleton:-
+(RootViewController*)sharedFirstViewController
{
#synchronized([RootViewController class])
{
if (!_sharedFirstViewController)
[[self alloc] init];
return _sharedFirstViewController;
}
return nil;
}
+(id)alloc
{
#synchronized([RootViewController class])
{
NSAssert(_sharedFirstViewController == nil,
#"Attempted to allocate a second instance of a singleton.");
_sharedFirstViewController = [super alloc];
return _sharedFirstViewController;
}
return nil;
}
-(id)init {
self = [super init];
if (self != nil) {
// initialize stuff here
}
return self;
}
after that you can use your variable in any other class like this
[RootViewController sharedFirstViewController].variable
Hope it's help you:)
With Storyboards the the right way is to pass the indexPath as sender argument in performSegueWithIdentifier
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"segueIdentifier" sender:indexPath];
}
and to set a property in the destination controller:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString: #"segueIdentifier"]) {
NSIndexPath *indexPath = sender;
DetailViewController *dest = [segue destinationViewController];
dest.usersArray = [self.usersArray objectAtIndex:indexPath.row];
}
}
What I have done whenever I needed another class to have the variables from the previous class I either set up a global class that will store the values incase I need them in more locations or in the interface you can set #public variables. These variables can be set using the controller that you created for the next view as such.
controller->pub_var1 = val1;
controller->pub_var2 = val2;
This will be done before you pass the view to the root controller or just before you call the next view. You will need to #import "class.h" so that you can access those public variables.
I can show code if this is not clear

Why is my delegate method not called?

this is probably simple but I'm stuck!
Basically I have a parent and child view controller, and I'm trying to pass data from the child to the parent.
//Child VC interface
#protocol ANSearchGetawayFilterDelegate
-(void)selectedCell:(NSString *)cellTitle;
#end
#interface ANSearchGetawayFilterViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
{
NSString* cellTitle;
}
#property (nonatomic, assign) id<ANSearchGetawayFilterDelegate> delegate;
#end
//Child VC implementation
#implementation ANSearchGetawayFilterViewController
#synthesize delegate = _delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellTitle = selectedCell.textLabel.text;
[[self delegate] selectedCell:cellTitle];
[self dismissModalViewControllerAnimated:YES];
}
//Parent VC interface
#import "ANSearchGetawayFilterViewController.h"
#interface ANGetawayFilterViewController : UIViewController <ANSearchGetawayFilterDelegate>
{
NSString* _cellText;
}
//Parent VC Implementation
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
search.delegate = self;
}
return self;
}
//delegate method
-(void)selectedCell:(NSString *)cellTitle
{
_cellText = cellTitle;
NSLog(#"cell text %#", _cellText);
}
the delegate method is never called and when is NSLog the _cellText else where it comes up as null...what am I doing wrong? Thanks!
You are most likely creating a new instance of ANSearchGetawayFilterViewController when you present it and not configuring the delegate on it.
When you called
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
search.delegate = self;
you created an instance of ANSearchGetawayFilterViewController and then set the delegate up correctly, but you never stored this instance of ANSearchGetawayFilterViewController anywhere. So later on when you come to present it you call again
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
which gives you a completely different instance, which you then need to configure again. For example
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
ANSearchGetawayFilterViewController *search1 = [[ANSearchGetawayFilterViewController alloc] init];
NSLog(#"%d", search1 == search);
#=> 0
To fix update your code to be
- (BOOL)textFieldShouldBeginEditing:(UITextField*)textField;
{
BOOL shouldBeginEditing = YES;
NSLog(#"text field should begin editing");
ANSearchGetawayFilterViewController *myANSearchGetawayFilterViewController = [[[ANSearchGetawayFilterViewController alloc] init] autorelease];
myANSearchGetawayFilterViewController.delegate = self; // <--- configure the delegate
[self presentModalViewController:myANSearchGetawayFilterViewController animated:YES];
[self closeAllPickers];
return shouldBeginEditing;
}
I wouldn't make it an ivar as the likelihood is you will present this viewController momentarily just to select some data and then get rid of it, so it is probably safe to discard it and make a new one each time.
Au contraire, the delegate method is being called (hence the NSLog()). However, _cellText is (null) because the value being passed in is nil, ergo selectedCell.textLabel.text.
Firstly, are you sure that the -selectedCell method is being called?
You can do this by putting an NSLog() before or after -tableViewDidSelectRow...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
NSLog(#"TABLEVIEW DID SELECT ROW BEFORE -> %# <-", cellTitle);
[[self delegate] selectedCell:cellTitle];
NSLog(#"TABLEVIEW DID SELECT ROW DELEGATE CALLED");
...
}
Also, you might want to do some cleanup (optional)
Firstly, you are leaking in your initialisation method. Either set the ANGetawayFilterViewController as a property of the parent class using the delegate, or release it after you set the delegate.
Secondly, in the -tableViewDidSelectRow, your code assumes that the delegate has the -selectedCell method coded. If you don't have the method implemented, then the application will result in a crash. You can prevent this by checking to see if the delegate -respondsToSelector...:
if ([self.delegate respondsToSelector:#selector(selectedCell:)]) {
[self.delegate selectedCell:cellTitle];
}
Thirdly, the method of which is being called by the delegate to notify the parentViewController doesn't follow the general schema that delegate methods use, with the exception of -numberOfRowsInSection (UITableViewDelegate). Your method should contain the actual ANFilterGetawayViewController instance too:
- (void) filterGetawayViewController:(ANSearchGetawayFilterViewController *) controller didSelectCellWithTitle:(NSString *) title {
...
}
It can be called as such:
[self.delegate filterGetawayViewController:self didSelectCellWithTitle:cellTitle];
Are you using ARC? Because when the init function ends, your object (and it's reference to the delegate) are cleaned up. What happens if you make the search variable a global one (defining it in your header and initializing it in your code)?
Assuming you are using ARC:
You need to make a retained #property for your ANSearchGetawayFilterViewController instance. It will have been released by ARC by the time the delegate method is called. Do something like this.
#property (strong, nonatomic) ANSearchGetawayFilterViewController *search;
...
#synthesize search = _search;
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
self.search = [[ANSearchGetawayFilterViewController alloc] init];
self.search.delegate = self;
}
return self;
}
Not related to your problem, but best practice is to check if the delegate actually implements the method you expect it to before calling it, like so:
if ([self.delegate respondsToSelector:#selector(selectedCell:)]) {
[self.delegate selectedCell:cellTitle];
}

Application tried to push a nil view controller on target <UINavigationController

In my Iphone app I have this pb :Application tried to push a nil view controller on target <UINavigationController:
I have a view controller that contains a tableview and I want that if one row is selected an other view controller to be displayed.
Here is my code :
in RecherchePartenaireViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==3){
NSLog(#"RecherchePartenaireDistanceViewController...");
recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController alloc] init];
self.recherchePartenaireDistanceViewController=recherchePartenaireDistanceViewController.recherchePartenaireViewController;
[self.navigationController pushViewController:recherchePartenaireDistanceViewController animated:YES];
[recherchePartenaireDistanceViewController release];
}
}
In RecherchePartenaireDistanceViewController.h :
#class RecherchePartenaireViewController;
#interface RecherchePartenaireDistanceViewController : UIViewController {
RecherchePartenaireViewController *recherchePartenaireViewController;
}
#property (nonatomic, retain) IBOutlet RecherchePartenaireViewController *recherchePartenaireViewController;
#end
and in RecherchePartenaireDistanceViewController.m
#import "RecherchePartenaireDistanceViewController.h"
#import "RecherchePartenaireViewController.h"
#implementation RecherchePartenaireDistanceViewController
#synthesize recherchePartenaireViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
[recherchePartenaireViewController release];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Where is the problem? I really can't see it. Please heeelp....
Try to use this:
- (void)dealloc
{
[recherchePartenaireViewController release];
[super dealloc];
}
instead of
- (void)dealloc
{
[super dealloc];
[recherchePartenaireViewController release];
}
I think I see what you're doing but I don't understand what you're trying to achieve! You have a ViewController that contains another view controller?
i.e. RecherchePartenaireDistanceViewController contains a RecherchePartenaireViewController
I assume that as it's an IBOutlet you're populating it using a xib file.
The only thing I can think of is that something is going wrong with the creation of your RecherchePartenaireDistanceViewController in the xib file.
What do you see in the console if you do this :
NSLog(#"controller : %#", recherchePartenaireDistanceViewController);
just before adding it to the navigation controller?
PS
What's the purpose of this line?
self.recherchePartenaireDistanceViewController=recherchePartenaireDistanceViewController.recherchePartenaireViewController;
if RecherchePartenaireDistanceViewController is with xib interface than use following statement while initializing,
recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController alloc] initWithNibName:#"RecherchePartenaireDistanceViewController" bundle:nil];
than push it to navigation controller.

Tableview not drilling down

Ok, Here is the code in my AppDelegate that loads the Schedule nib.
Schedule *newestVideoController = [[Schedule alloc] initWithNibName:#"Schedule" bundle:nil];
newestVideoController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Schedule" image:[UIImage imageNamed:#"app-icon_2_newest.png"] tag:2];
NSArray *controllers = [NSArray arrayWithObjects:navController, newestVideoController, nil];
mainController.viewControllers = controllers;
Now here is my header file for schedule.
#import <UIKit/UIKit.h>
#import "AnotherViewController.h"
#interface Schedule : UITableViewController
<UITableViewDelegate, UITableViewDataSource> {
NSArray *mySchedule;
}
#property (nonatomic,retain) NSArray *mySchedule;
#end
Lastly here again is my implementaion file for "Schedule".
#import "Schedule.h"
#import "AnotherViewController.h"
#implementation Schedule
#synthesize mySchedule;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return mySchedule.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//create a cell
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
//fill it with contents
cell.textLabel.text = [mySchedule objectAtIndex:indexPath.row];
//return it
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherViewController" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *myFile = [[NSBundle mainBundle] pathForResource:#"exercise" ofType:#"plist"];
mySchedule = [[NSArray alloc] initWithContentsOfFile:myFile];
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
Need more code/info. It looks like you implemented tableView:didSelectRowAtIndexPath: and pushed another View Controller onto the stack correctly, so it's hard to say. But here's a hit list:
Are you certain tableView:didSelectRowAtIndexPath: is getting called? Did you set a breakpoint? If not, you may have forgotten to set your Schedule class as the delegate either programatically or in Interface Builder.
Is schedule's navigation controller definitely set? That is, was it pushed onto a Navigation Controller stack?
Are you sure the nib file for AnotherViewController exists?

UITableViewController problems

I have a nib that contains two TableViews. The table views are of the same class that I have created that is a subclass of a UITableViewController. I believe that everything is hooked up correctly. However, when I set the UITableView to the UITableViewController then run
[uitableviewcontrollervariablename reloadData];
I first get a warning that the class may not respond to reloadData. I thought all UITableViewControllers had a reloadData class?
I am trying to hook up these items incorrectly?
Update with code:
TopicViewController.h
#interface TopicViewController : UIViewController {
NSInteger topicID;
Topic *topic;
IBOutlet ThoughtTableViewController *featured;
}
#property (retain) Topic *topic;
#property (readonly) NSInteger topicID;
#property (retain) IBOutlet ThoughtTableViewController *featured;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil ID:(NSInteger)ID;
#end
TopicViewController.m
#implementation TopicViewController
#synthesize topic;
#synthesize topicID;
#synthesize featured;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil ID:(NSInteger)ID {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
topicID = ID;
}
return self;
}
- (void)dealloc {
[topic release];
[super dealloc];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
topic = [[Topic alloc] initWithID:topicID];
NSArray *thoughts = [topic getFeaturedThoughts];
featured = [[ThoughtTableViewController alloc] initWithStyle:UITableViewStylePlain thoughts:thoughts];
[self.featured.tableView reloadData];
}
#end
Your hookups are fine… you just have to call that method on the TableView class, not the controller:
[uitableviewcontrollervariablename.tableView reloadData];
EDIT: 10/20/09
Its kind-of tough to see what is going on because you are using IB instead of programatically adding the tables but the hookups should be like this:
UIViewController owns two UITableViews, not two UITableViewControllers
UIViewController acts as a UITableViewDataSource, UITableViewDelegate
Asking each of the tableViews to reload will ask the DataSource for data, in which you will have to differentiate between the two
Here is some code as an example how to do it programatically:
#interface WhateverController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
…
UITableView *tableView1;
UITableView *tableView2;
}
#end
-
#implementation WhateverController
…
- (void)loadView {
[super loadView];
tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(YOUR_FRAME_1)];
tableView2 = [[UITableView alloc] initWithFrame:CGRectMake(YOUR_FRAME_2)];
tableView1.delegate = self;
tableView2.delegate = self;
tableView1.dataSource = self;
tableView2.dataSource = self;
[self.view addSubview:tableView1];
[self.view addSubview:tableView2];
}
-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == tableView1) {
// return a cell using the data for tableView1
} else if (tableView == tableView2) {
// return a cell using the data for tableView2
}
}
So you will add all the UITableViewDelegate methods and UITableViewDataSource methods you will need to populate the 2 tableViews. When you want to reload the data:
[tableView1 reloadData];
[tableView2 reloadData];