Skip to content

Commit

Permalink
master:合并dev,增加了笔记的TableView,实现了Header的点击
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyufeng1991 committed Nov 12, 2015
2 parents 1a1aaba + f9049b6 commit 61ea413
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Oncenote/Assets.xcassets/tableview_arrow.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "QQ20151113-1@2x副本.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Oncenote/Assets.xcassets/tableview_note.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "tableview_note@2x副本.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions Oncenote/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,36 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="zVu-dn-TfY">
<rect key="frame" x="12" y="159" width="296" height="196"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="NoteCell" id="5Sh-dK-bIY">
<rect key="frame" x="0.0" y="28" width="296" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="5Sh-dK-bIY" id="JSL-YX-K0G">
<rect key="frame" x="0.0" y="0.0" width="296" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</tableViewCellContentView>
<animations/>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="P6V-Vs-eG7"/>
<outlet property="delegate" destination="BYZ-38-t0r" id="NiU-Kc-xHK"/>
</connections>
</tableView>
</subviews>
<animations/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
</view>
<navigationItem key="navigationItem" title="主界面" id="Bs1-GG-Xfh"/>
<connections>
<outlet property="noteTableView" destination="zVu-dn-TfY" id="kIH-5t-HVn"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
Expand Down
97 changes: 96 additions & 1 deletion Oncenote/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@
// Copyright © 2015年 chenyufengweb. All rights reserved.
//


/*
界面的背景灰色:[UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1]
主色调绿色:[UIColor colorWithRed:0 green:0.6 blue:0.26 alpha:1]
*/

#import "ViewController.h"

@interface ViewController ()
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *noteTableView;//“笔记”的TableView


@property(nonatomic,strong) NSArray *noteArray;

@end

Expand All @@ -19,6 +32,9 @@ - (void)viewDidLoad {

[self setNavigationBarItemButton];

//添加数据
self.noteArray = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];


}

Expand Down Expand Up @@ -90,6 +106,85 @@ - (void)naviSearchButtonPressed:(id)sender{
[self presentViewController:alert animated:true completion:nil];

}

- (void)noteHeaderPressed:(id)sender{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"这是TableView头部" preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//点击按钮的响应事件;
}]];

[self presentViewController:alert animated:true completion:nil];

}


#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NoteCell" forIndexPath:indexPath];
cell.textLabel.text = [self.noteArray objectAtIndex:indexPath.row];
return cell;

}

// fixed font style. use custom view (UILabel) if you want something different
//- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//
// return @"这是头部";
//}





#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 50;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width , 50)];

//需要在Header底部加一条细线,用来分隔第一个cell;默认Header和第一个cell之间是没有分隔线的;

UIImageView *noteIcon = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
[noteIcon setImage:[UIImage imageNamed:@"tableview_note.png"]];

UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 10, 50, 30)];
noteLabel.text = @"笔记";
noteLabel.textColor = [UIColor colorWithRed:0 green:0.6 blue:0.26 alpha:1];

UILabel *totalLabel = [[UILabel alloc] initWithFrame:CGRectMake(tableView.bounds.size.width - 60, 10, 50, 30)];
totalLabel.text = @"全部";
totalLabel.textColor = [UIColor colorWithRed:0 green:0.6 blue:0.26 alpha:1];
totalLabel.font = [UIFont systemFontOfSize:12];

UIImageView *arrowIcon = [[UIImageView alloc] initWithFrame:CGRectMake(tableView.bounds.size.width - 30, 10, 30, 30)];
[arrowIcon setImage:[UIImage imageNamed:@"tableview_arrow.png"]];

[view addSubview:noteIcon];
[view addSubview:noteLabel];
[view addSubview:totalLabel];
[view addSubview:arrowIcon];

//增加Header的点击事件;
[view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(noteHeaderPressed:)]];

return view;

}

@end


Expand Down

0 comments on commit 61ea413

Please sign in to comment.