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:-
.m file:-
@ implementation RoutviewController
# program mark view life cycle:
// add method:
-(void) add click
[ a Array addObject : @ “hello”];
# program mark-
# program mark table view data source:
{
Rreturn 1;
}
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];
}
Subscribe to our youtube channel to get new updates..!
Commit editing Style:(UITableviewcellEditingStyle)
Editing style for RowAtIndexPath:(NSIndePath *)index path
{
If (editing style = = UITable view cell editing style delete)
{
delete the row from the data source:
[ 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)
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:-
@ interface second view: UITable viewController
{
}
@end
Capture 15Second view . m:-
# program mark view life cycle:
{
[Super viewDidLoad];
Self . title = @ “Second view”;
How To Add Bar Button Dynamically:
[[UIBarButtonItem alloc] initWithTitle:@ “Back”
Style: UIBarButtonItem style Bordered target: self
Action : @ selector (back)];
Self. Navigation Item. RightBarButtonItem = self. edit ButtonItem;
}
-(void) Back
{
}
# program mark table view data source:
(UITable view *) table view
{
return 1;
}
Number ofRowsInsection : ( NSInteger) Section
{
Return 4;
}
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:-
{
IBoutlet UIImage view * img view;
IBoutlet UIpicker view *Pview;
NSMutableArray * aArray;
}
@end
.m file:-
{
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:
{
return 1;
}
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);
}
Frequently Asked iPhone Interview Questions & Answers