Mindmajix

iPhone – Navigation Based Controller

Navigation Based Controller

A navigation controller manages a stack of view controllers to provide a drill-down interface for hierarchical content. The view hierarchy of a navigation controller is self contained. It is composed of views that the navigation controller manages directly and views that are managed by content view controllers you provide. Each content view controller manages a distinct view hierarchy, and the navigation controller coordinates the navigation between these view hierarchies.

.h file:-

# import <UIKIT/UIKIT .h>
#import    “Second view .h”
@ interface rout view controller: UI table view controller
{
NSMutable  Array     * aArray;
}
@ end

 .m file:-

# import “Root viewController. h”

@ implementation RoutviewController

 


# program mark view life cycle:

Capture 15

-(void) view Didload
{
[ Super   viewDidLoad];
AArray  =  [[ NSMutableArray  alloc]  initWithObjects:
@ “one”, @ “two”, @ “three”, @ “four”, @ “five”, nil];
[ array retain];
Self title  =  @ “ Navigation  Based”;
Self . navigationItem . rightBarButtonItem = self. editButtonItem;

Capture 15// add method:

UI BarButton item     * leftButtonItem = [[ UIButtonItem alloc]
InitwithTitle  : @ “add”
Style          : UIBar ButtonItemStyle Bordered
Target   : self
Action      :   @ selector  ( Add click)];
Self . navigationItem  . leftBarButtonItem. LeftBarButtonItem
}

Capture 15

-(void) add click
{
[ a Array addObject  :   @  “hello”];
[ self. table view   reload Data];
}

# program mark-

# program mark table view data source:

Capture 15

-(NSInteger) numberofSectionIn Tableview : (UI Table view    *) table view
{
Rreturn 1;
}

Capture 15

-(UITable view cell     *) table view  :   (UITableview      *) table view
CellForRowAtIndexPath: (NSIndex path     *) indexpath
{
Static  NSString   * cell Identifier  =  @  “cell”;
UITable  view cell      * cell    =    [ table view
DequeueReusableCellWithIdentifier  :  cellIdentifier];
If (cell  = = nil)
{
Cell  =  [[[UITableviewcell alloc] init with style:
UI Table view cell Style Default   reuseIdentifier :  cell Identifier
                                                      Auto release];
}
[cell setAccessory Type: UITableviewcellAccessory
                         DisclosureIndicator];
Cell. textLabel. Text = [aArray object At Index: indexpath.row];
Return cell;
}
-(NSInteger) table view: (UITable view     *)    table view
NumberofRowsInSection : (NSInteger) section
{
Return  [  array count];
}

Capture 15

-(void) table view: (UITable view    *)  table view
Commit editing Style:(UITableviewcellEditingStyle)
Editing style for RowAtIndexPath:(NSIndePath   *)index path
{
If (editing style  = = UITable view cell editing style delete)
{

Capture 15// delete the row from the data source:

[ aArray removeObjectAtIndex: indexpath.row];
[ tableview deleteRowAtIndexpaths : [NSArray
Array with object: index path]
With row animation: UITableViewRowAnimationFade];
}
Else if (editing style = = UITableviewcellEditingStyleInsert)
{
}
}

# program mark:-

# program mark memory management ( Table view Delegate)

Capture 15

-(void) table view: (UITable view       *) table view
DidselectRow At Indexpath: ( NSIndex path     *) index path
{
NSLog ( @ “didSelectRowAtIndexPath called”);
Second view     * secondviewController  =  [[ secondview alloc]
InitWithNibNames: @ “second view” bundle  :nil];
[self. NavigationController pushviewController: secondviewController animated : yes];
}

Second view .h:-

# import  <UIKIT/UIKIT>
@ interface second view: UITable viewController
{
}
@end

Capture 15Second view . m:-

@ implementation secondview

# program mark view life cycle:

-(void) view did load
{
[Super viewDidLoad];
Self . title = @ “Second view”;

Capture 15// How To Add Bar Button Dynamically:

UIBarButtonItem   * leftBarButtonItem =
[[UIBarButtonItem alloc]  initWithTitle:@ “Back”

Style: UIBarButtonItem style Bordered target: self

Action  :  @ selector (back)];

Self. Navigation Item .leftBarButtonItem  =  leftBarButtonItem;
Self.  Navigation Item. RightBarButtonItem = self. edit ButtonItem;
}
-(void) Back
{

[self. NavigationController popviewControllerAnimated :YES];
}

# program mark table view data source:

Capture 15

-(NSInteger) number of sections in Table view:
(UITable view     *) table view
{
return  1;
}

Capture 15

-(NSInteger) table view: (UITable view   *) table view
Number ofRowsInsection : ( NSInteger) Section
{
Return  4;
}

Capture 15

-(UITable view cell    *)  table view   :(UITable view     *)
Table view cellForRowAtIndex path  :(NSIndex     *)index path
{
Static   NSString     *   cellIdentifier   =   @   “cell”;
UITable  cell     * cell= [table view
Dequeusable cell withIdentifier: cellIdentifier]
If  (cell = nil)
{
Cell  =   [[[ u Tableview cell alloc]   init with style:
UITable  view cell Style De fault  reuseIdentifier:
Cell identifier]  auto release];
}
Cell table text. Text= @ “hello”;
Return cell;
}

Image picker view with UI image view and ns mutable array:-

.h file:-

# import   <UIKIT/UIKIT .h>
@ interface divpickerviewController  : UIview controller
{
IBoutlet   UIImage view    * img view;
IBoutlet   UIpicker view   *Pview;
NSMutableArray      * aArray;
}
@end

.m file:-

-(void) view Didload
{
P view . delegate  =  self;
P view . data source  =  self;
aArray   =  [[NSMutable Array  alloc]
InitWithObjects: @  “blue” @ “red” @ “green” @ “pink”, @ “yellow”, nil];
[ super view DidLoad];
}

-(NSInteger) number of components in picker view:

(UI picker view        *) picker view
{
return    1;
}
-(NSInteger)  picker view:  (UIPicker view    *) picker view
NumberOfRowsInComponent   :(NSInteger) component
{
return [ aArray  count];
}
-(NSString    *) picker view.  (  UIpickerview      *)  pickerview
Title forRow :   (NSInteger)  row for  Component:
(NSInteger)Component
{
return  [  array   objectAtIndex :row];
}
-(CG Float) pickerview:  (UIpickerview       *)    picker view
row heightForComponent (NSInteger) Component
{
return   150;
}
-(UIView     *)   picker view   :  (UIPickerview     *)  pickerview
ViewForRow:  (NSInteger)row  forComponent:
(NSInteger)Component     reusing view:  (UI view    *)view
{
Imgview  =[[ UIImage  view  alloc]  initWithFrame:
                   CGRectMake  (100,80,100,70)];
Imgview. Image   =  UIImage    imageNamed:
                                @ “hollowoody2.gif”];
return imgview;
}
-(void)  pickerview: (UIpickerview     *) pickerview
DidselectRow:  (NSInteger) row in Component:
                             (NSInteger) Component
{
NSLog  (@  “did SelectRow  is called and row is %d
Row  is %d  and  Component   is %d”, row, component);
}

0 Responses on iPhone – Navigation Based Controller"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.