#在蓝懿学习iOS的日子 #day13

Source: Internet
Author: User

I. Navigation controller Navigationcontroeller Add a navigationcontroeller before the first Viewcontroller, create a new second page SecondViewController1, VIEWCONTROLLER.M import #import "SecondViewController.h" @implementation Viewcontroller
-(Ibaction) Leftaction: (Uibarbuttonitem *) Sender {
NSLog (@ "left button");
}
-(Ibaction) clicked: (ID) Sender {
Secondviewcontroller *VC = [[Secondviewcontroller alloc]init];
[Self.navigationcontroller PUSHVIEWCONTROLLER:VC Animated:yes];

}

-(void) Viewdidload {
[Super Viewdidload];
Create a System Style button
Uibarbuttonitem *bbi1 = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera Target:self Action: @selector (rightaction)];

Create Text button
Uibarbuttonitem *BBI2 = [[Uibarbuttonitem alloc]initwithtitle:@ ' right button ' Style:uibarbuttonitemstyledone target:self Action: @selector (rightaction)];

Self.navigationItem.rightBarButtonItems = [Nsarray arraywithobjects:bbi1,bbi2, Nil];
Self.navigationItem.rightBarButtonItems = @[bbi1,bbi2];


}
-(void) rightaction{
NSLog (@ "right button");} 2, in secondviewcontroller.m-(void) Viewdidload {
[Super Viewdidload];
Self.title = @ "Second page";

[Nstimer scheduledtimerwithtimeinterval:2 target:self selector: @selector (backaction) Userinfo:nil Repeats:no];
}
-(void) backaction{
Skip back to Previous page
[Self.navigationcontroller Popviewcontrolleranimated:yes];} Second, UITableView
@interface Viewcontroller () <UITableViewDataSource,UITableViewDelegate>
@property (Weak, nonatomic) Iboutlet UITableView *tableview;
@property (nonatomic, strong) Nsmutablearray *names;
@end

@implementation Viewcontroller
There are several areas of control TableView
-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{
return 1;
}
Control how many rows are in each area
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{


return self.names.count;
}


Control what is displayed on each line
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{



Go to the memory to find the cell that has not left the page to have a word to take it directly with no then nil
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:@ "Cell"];
If you do not get the cell leaving the page, you need to create a
if (!cell) {
cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:@ "Cell"];
NSLog (@ "%ld-%ld", Indexpath.section,indexpath.row);
}

NSString *name = Self.names[indexpath.row];


Cell.textLabel.text = name;
return cell;
}

-(void) Viewdidload {
[Super Viewdidload];

Self.names = [Nsmutablearray array];

[Self.names addobject:@ "Andy Lau"];
[Self.names addobject:@ "Jacky"];
[Self.names addobject:@ "Aaron Kwok"];

Uibarbuttonitem *additem = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemadd Target:self Action: @selector (Addaction)];
Self.navigationItem.leftBarButtonItem = AddItem;
}

-(void) addaction{
NSString *name = @ "King";
[Self.names Addobject:name];
To modify the data source array after the Viewdidload method, you need to let TableView reload
[Self.tableview Reloaddata];


}

#在蓝懿学习iOS的日子 #day13

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.