Skip to content

Commit 0bed21b

Browse files
Merge pull request #10 from LeoMobileDeveloper/develop
v 0.4.0
2 parents 85aad80 + 517cdaa commit 0bed21b

24 files changed

Lines changed: 571 additions & 62 deletions

Demo/Base.lproj/Main.storyboard

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,55 @@
2121
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2222
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2323
<subviews>
24-
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kmx-NE-WpS">
25-
<rect key="frame" x="158" y="318" width="59" height="30"/>
26-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
27-
<state key="normal" title="Click Me"/>
24+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kmx-NE-WpS">
25+
<rect key="frame" x="148.5" y="298.5" width="78" height="30"/>
26+
<state key="normal" title="Core Demo"/>
2827
<connections>
2928
<segue destination="UfB-hx-yKX" kind="show" id="rwT-RC-hCA"/>
3029
</connections>
3130
</button>
31+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5Qj-J6-yeM">
32+
<rect key="frame" x="121.5" y="338.5" width="132" height="30"/>
33+
<state key="normal" title="UIResponser Demo"/>
34+
<connections>
35+
<segue destination="qXn-Nz-YLY" kind="show" id="NgL-qB-NZJ"/>
36+
</connections>
37+
</button>
3238
</subviews>
3339
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
40+
<constraints>
41+
<constraint firstItem="5Qj-J6-yeM" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" constant="20" id="4Xx-Ce-r87"/>
42+
<constraint firstItem="5Qj-J6-yeM" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="98x-RA-7Qa"/>
43+
<constraint firstItem="kmx-NE-WpS" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="qpU-9k-8wE"/>
44+
<constraint firstItem="kmx-NE-WpS" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" constant="-20" id="x16-jO-7Vw"/>
45+
</constraints>
3446
</view>
3547
<navigationItem key="navigationItem" id="CQU-Sg-UIy"/>
3648
</viewController>
3749
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
3850
</objects>
3951
<point key="canvasLocation" x="719" y="-564"/>
4052
</scene>
41-
<!--Demo-->
53+
<!--UIResponser Demo-->
54+
<scene sceneID="st6-5p-095">
55+
<objects>
56+
<tableViewController id="qXn-Nz-YLY" customClass="DemoTableViewController" sceneMemberID="viewController">
57+
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="rcc-Yl-Ibx">
58+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
59+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
60+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
61+
<connections>
62+
<outlet property="dataSource" destination="qXn-Nz-YLY" id="NAN-bd-r0Z"/>
63+
<outlet property="delegate" destination="qXn-Nz-YLY" id="2ji-vv-VPC"/>
64+
</connections>
65+
</tableView>
66+
<navigationItem key="navigationItem" title="UIResponser Demo" id="eUW-sA-z4b"/>
67+
</tableViewController>
68+
<placeholder placeholderIdentifier="IBFirstResponder" id="9Oz-M2-GIa" userLabel="First Responder" sceneMemberID="firstResponder"/>
69+
</objects>
70+
<point key="canvasLocation" x="1666" y="-343"/>
71+
</scene>
72+
<!--Core-->
4273
<scene sceneID="8Zq-hH-jqD">
4374
<objects>
4475
<viewController id="UfB-hx-yKX" customClass="DemoViewController" sceneMemberID="viewController">
@@ -58,7 +89,7 @@
5889
</connections>
5990
</button>
6091
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DAf-9g-R9z">
61-
<rect key="frame" x="115.5" y="274.5" width="144" height="30"/>
92+
<rect key="frame" x="115.5" y="280.5" width="144" height="30"/>
6293
<state key="normal" title="Dispatch Notification"/>
6394
<connections>
6495
<action selector="dispatchNotification:" destination="UfB-hx-yKX" eventType="touchUpInside" id="XZN-wZ-wqm"/>
@@ -71,22 +102,39 @@
71102
<action selector="dispatchString:" destination="UfB-hx-yKX" eventType="touchUpInside" id="8D8-wz-two"/>
72103
</connections>
73104
</button>
105+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Click and view log " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bJe-KU-79l">
106+
<rect key="frame" x="116.5" y="84" width="142" height="21"/>
107+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
108+
<nil key="textColor"/>
109+
<nil key="highlightedColor"/>
110+
</label>
111+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Og7-Wh-LQt">
112+
<rect key="frame" x="135" y="394" width="105" height="30"/>
113+
<state key="normal" title="Dispatch JSON"/>
114+
<connections>
115+
<action selector="dispatchJson:" destination="UfB-hx-yKX" eventType="touchUpInside" id="WCe-sY-ZWU"/>
116+
</connections>
117+
</button>
74118
</subviews>
75119
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
76120
<constraints>
77121
<constraint firstItem="MXl-SO-nrb" firstAttribute="centerY" secondItem="gBg-dr-YJh" secondAttribute="centerY" id="0ee-IM-VqN"/>
78122
<constraint firstItem="Gzk-EX-vLV" firstAttribute="top" secondItem="MXl-SO-nrb" secondAttribute="bottom" constant="7.5" id="CxM-iL-nxJ"/>
79123
<constraint firstItem="MXl-SO-nrb" firstAttribute="centerX" secondItem="gBg-dr-YJh" secondAttribute="centerX" id="DQZ-jE-IBh"/>
80124
<constraint firstItem="DAf-9g-R9z" firstAttribute="centerX" secondItem="MXl-SO-nrb" secondAttribute="centerX" id="Dz4-ce-Yux"/>
125+
<constraint firstItem="bJe-KU-79l" firstAttribute="top" secondItem="eOf-31-Oau" secondAttribute="bottom" constant="20" id="KJx-M1-fns"/>
126+
<constraint firstItem="bJe-KU-79l" firstAttribute="centerX" secondItem="gBg-dr-YJh" secondAttribute="centerX" id="RuX-sw-sfz"/>
127+
<constraint firstItem="Og7-Wh-LQt" firstAttribute="top" secondItem="Gzk-EX-vLV" secondAttribute="bottom" constant="8" id="VDX-q6-HJR"/>
81128
<constraint firstItem="Gzk-EX-vLV" firstAttribute="centerX" secondItem="MXl-SO-nrb" secondAttribute="centerX" id="fN7-kG-dEe"/>
82-
<constraint firstItem="MXl-SO-nrb" firstAttribute="top" secondItem="DAf-9g-R9z" secondAttribute="bottom" constant="14" id="uup-6p-Jot"/>
129+
<constraint firstItem="Og7-Wh-LQt" firstAttribute="centerX" secondItem="Gzk-EX-vLV" secondAttribute="centerX" id="hFn-h7-v7J"/>
130+
<constraint firstItem="MXl-SO-nrb" firstAttribute="top" secondItem="DAf-9g-R9z" secondAttribute="bottom" constant="8" id="uup-6p-Jot"/>
83131
</constraints>
84132
</view>
85-
<navigationItem key="navigationItem" title="Demo" id="4Hn-Xo-L8m"/>
133+
<navigationItem key="navigationItem" title="Core" id="4Hn-Xo-L8m"/>
86134
</viewController>
87135
<placeholder placeholderIdentifier="IBFirstResponder" id="8QO-bK-JYK" userLabel="First Responder" sceneMemberID="firstResponder"/>
88136
</objects>
89-
<point key="canvasLocation" x="1476" y="-564"/>
137+
<point key="canvasLocation" x="1711" y="-1065"/>
90138
</scene>
91139
<!--Navigation Controller-->
92140
<scene sceneID="Rtc-PG-pnE">
File renamed without changes.
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ - (void)viewDidLoad {
3535
[QTSubName(self, @"ButtonClickedEvent") next:^(NSString *event) {
3636
NSLog(@"%@",@"Receive String Event");
3737
}];
38+
[QTSubJSON(self, @"EventKey") next:^(QTJsonEvent *event) {
39+
NSLog(@"Receive Json Event: %@",event.data);
40+
}];
3841
}
3942

4043

@@ -54,6 +57,12 @@ - (IBAction)dispatchString:(id)sender {
5457
[[QTEventBus shared] dispatch:@"ButtonClickedEvent"];
5558
}
5659

60+
- (IBAction)dispatchJson:(id)sender {
61+
QTJsonEvent * event = [QTJsonEvent eventWithId:@"EventKey"
62+
jsonObject:@{@"Author" : @"LeoMobileDeveloper"}];
63+
[[QTEventBus shared] dispatch:event];
64+
}
65+
5766
- (void)dealloc{
5867
NSLog(@"Dealloc: %@",NSStringFromClass(self.class));
5968
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// DemoTableViewCell.h
3+
// Demo
4+
//
5+
// Created by Leo on 2018/11/18.
6+
// Copyright © 2018 Leo Huang. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "QTEventBus+UIKit.h"
11+
12+
extern NSString * const Button1ClickedEvent; // 不带数据的Event
13+
14+
// 携带数据的Event
15+
@interface Button2ClickEvent : NSObject<QTEvent>
16+
17+
@property (strong, nonatomic) UITableViewCell * cell;
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
@interface DemoTableViewCell : UITableViewCell
24+
@property (weak, nonatomic) IBOutlet UILabel *indexLabel;
25+
26+
@end
27+
28+
NS_ASSUME_NONNULL_END
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// DemoTableViewCell.m
3+
// Demo
4+
//
5+
// Created by Leo on 2018/11/18.
6+
// Copyright © 2018 Leo Huang. All rights reserved.
7+
//
8+
9+
#import "DemoTableViewCell.h"
10+
11+
NSString * const Button1ClickedEvent = @"Button1ClickedEvent"; // 不带数据的Event
12+
13+
@implementation Button2ClickEvent
14+
15+
@end
16+
17+
@implementation DemoTableViewCell
18+
19+
- (void)awakeFromNib {
20+
[super awakeFromNib];
21+
// Initialization code
22+
}
23+
24+
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
25+
[super setSelected:selected animated:animated];
26+
27+
// Configure the view for the selected state
28+
}
29+
30+
- (IBAction)button1Clicked:(id)sender {
31+
[self.eventDispatcher dispatch:Button1ClickedEvent];
32+
}
33+
34+
- (IBAction)button2Clicked:(id)sender {
35+
Button2ClickEvent * event = [[Button2ClickEvent alloc] init];
36+
event.cell = self;
37+
[self.eventDispatcher dispatch:event];
38+
}
39+
40+
@end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<objects>
12+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
13+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14+
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="DemoTableViewCell">
15+
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
16+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
17+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
18+
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
19+
<autoresizingMask key="autoresizingMask"/>
20+
<subviews>
21+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5Lf-zH-Cg9">
22+
<rect key="frame" x="63" y="7" width="57" height="30"/>
23+
<state key="normal" title="Button 1"/>
24+
<connections>
25+
<action selector="button1Clicked:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="A94-qh-4ei"/>
26+
</connections>
27+
</button>
28+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="642-Gh-KSM">
29+
<rect key="frame" x="249" y="7" width="55" height="30"/>
30+
<state key="normal" title="Button2"/>
31+
<connections>
32+
<action selector="button2Clicked:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="B5o-9o-hmm"/>
33+
</connections>
34+
</button>
35+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sZ6-AK-gcQ">
36+
<rect key="frame" x="8" y="11.5" width="42" height="21"/>
37+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
38+
<nil key="textColor"/>
39+
<nil key="highlightedColor"/>
40+
</label>
41+
</subviews>
42+
<constraints>
43+
<constraint firstItem="5Lf-zH-Cg9" firstAttribute="leading" secondItem="sZ6-AK-gcQ" secondAttribute="trailing" constant="13" id="EAw-hf-6ce"/>
44+
<constraint firstItem="5Lf-zH-Cg9" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="Urp-xt-Zrj"/>
45+
<constraint firstItem="642-Gh-KSM" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="YqV-ui-BIZ"/>
46+
<constraint firstAttribute="trailing" secondItem="642-Gh-KSM" secondAttribute="trailing" constant="16" id="e5P-rn-6j4"/>
47+
<constraint firstItem="sZ6-AK-gcQ" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="8" id="eAR-Ju-iBM"/>
48+
<constraint firstItem="sZ6-AK-gcQ" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="qeB-K6-UBv"/>
49+
</constraints>
50+
</tableViewCellContentView>
51+
<connections>
52+
<outlet property="indexLabel" destination="sZ6-AK-gcQ" id="4Zb-ie-cYd"/>
53+
</connections>
54+
<point key="canvasLocation" x="50" y="97"/>
55+
</tableViewCell>
56+
</objects>
57+
</document>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// DemoTableViewController.h
3+
// Demo
4+
//
5+
// Created by Leo on 2018/11/18.
6+
// Copyright © 2018 Leo Huang. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface DemoTableViewController : UITableViewController
14+
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// DemoTableViewController.m
3+
// Demo
4+
//
5+
// Created by Leo on 2018/11/18.
6+
// Copyright © 2018 Leo Huang. All rights reserved.
7+
//
8+
9+
#import "DemoTableViewController.h"
10+
#import "DemoTableViewCell.h"
11+
12+
@interface DemoTableViewController ()
13+
14+
@end
15+
16+
@implementation DemoTableViewController
17+
18+
- (void)viewDidLoad {
19+
[super viewDidLoad];
20+
[self.tableView registerNib:[UINib nibWithNibName:@"DemoTableViewCell" bundle:nil]
21+
forCellReuseIdentifier:@"cell"];
22+
//弱持有Self,因为self持有EventBus,EventBus持有block
23+
__weak typeof(self) weakSelf = self;
24+
25+
//Cell中Button1点击,采用String来唯一区分
26+
[[self subscribeName:Button1ClickedEvent on:self.eventDispatcher]
27+
next:^(NSString *event) {
28+
NSLog(@"Button 1 clicked");
29+
}];
30+
31+
//Cell中Button2点击,采用类来区分
32+
[[self subscribe:Button2ClickEvent.class on:self.eventDispatcher]
33+
next:^(Button2ClickEvent * event) {
34+
NSIndexPath * indexPath = [weakSelf.tableView indexPathForCell:event.cell];
35+
NSLog(@"Button 2 in cell %ld clicked",(long)indexPath.row);
36+
}];
37+
}
38+
39+
#pragma mark - Table view data source
40+
41+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
42+
return 1;
43+
}
44+
45+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
46+
return 10;
47+
}
48+
49+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
50+
DemoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
51+
cell.indexLabel.text = @(indexPath.row).stringValue;
52+
return cell;
53+
}
54+
55+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
56+
return 50.0;
57+
}
58+
59+
60+
@end

0 commit comments

Comments
 (0)