-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from LeoMobileDeveloper/develop
v 0.4.0
- Loading branch information
Showing
24 changed files
with
571 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// DemoTableViewCell.h | ||
// Demo | ||
// | ||
// Created by Leo on 2018/11/18. | ||
// Copyright © 2018 Leo Huang. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "QTEventBus+UIKit.h" | ||
|
||
extern NSString * const Button1ClickedEvent; // 不带数据的Event | ||
|
||
// 携带数据的Event | ||
@interface Button2ClickEvent : NSObject<QTEvent> | ||
|
||
@property (strong, nonatomic) UITableViewCell * cell; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface DemoTableViewCell : UITableViewCell | ||
@property (weak, nonatomic) IBOutlet UILabel *indexLabel; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// DemoTableViewCell.m | ||
// Demo | ||
// | ||
// Created by Leo on 2018/11/18. | ||
// Copyright © 2018 Leo Huang. All rights reserved. | ||
// | ||
|
||
#import "DemoTableViewCell.h" | ||
|
||
NSString * const Button1ClickedEvent = @"Button1ClickedEvent"; // 不带数据的Event | ||
|
||
@implementation Button2ClickEvent | ||
|
||
@end | ||
|
||
@implementation DemoTableViewCell | ||
|
||
- (void)awakeFromNib { | ||
[super awakeFromNib]; | ||
// Initialization code | ||
} | ||
|
||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { | ||
[super setSelected:selected animated:animated]; | ||
|
||
// Configure the view for the selected state | ||
} | ||
|
||
- (IBAction)button1Clicked:(id)sender { | ||
[self.eventDispatcher dispatch:Button1ClickedEvent]; | ||
} | ||
|
||
- (IBAction)button2Clicked:(id)sender { | ||
Button2ClickEvent * event = [[Button2ClickEvent alloc] init]; | ||
event.cell = self; | ||
[self.eventDispatcher dispatch:event]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | ||
<device id="retina4_7" orientation="portrait"> | ||
<adaptation id="fullscreen"/> | ||
</device> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="DemoTableViewCell"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | ||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
<subviews> | ||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5Lf-zH-Cg9"> | ||
<rect key="frame" x="63" y="7" width="57" height="30"/> | ||
<state key="normal" title="Button 1"/> | ||
<connections> | ||
<action selector="button1Clicked:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="A94-qh-4ei"/> | ||
</connections> | ||
</button> | ||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="642-Gh-KSM"> | ||
<rect key="frame" x="249" y="7" width="55" height="30"/> | ||
<state key="normal" title="Button2"/> | ||
<connections> | ||
<action selector="button2Clicked:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="B5o-9o-hmm"/> | ||
</connections> | ||
</button> | ||
<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"> | ||
<rect key="frame" x="8" y="11.5" width="42" height="21"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<nil key="textColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<constraints> | ||
<constraint firstItem="5Lf-zH-Cg9" firstAttribute="leading" secondItem="sZ6-AK-gcQ" secondAttribute="trailing" constant="13" id="EAw-hf-6ce"/> | ||
<constraint firstItem="5Lf-zH-Cg9" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="Urp-xt-Zrj"/> | ||
<constraint firstItem="642-Gh-KSM" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="YqV-ui-BIZ"/> | ||
<constraint firstAttribute="trailing" secondItem="642-Gh-KSM" secondAttribute="trailing" constant="16" id="e5P-rn-6j4"/> | ||
<constraint firstItem="sZ6-AK-gcQ" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="8" id="eAR-Ju-iBM"/> | ||
<constraint firstItem="sZ6-AK-gcQ" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="qeB-K6-UBv"/> | ||
</constraints> | ||
</tableViewCellContentView> | ||
<connections> | ||
<outlet property="indexLabel" destination="sZ6-AK-gcQ" id="4Zb-ie-cYd"/> | ||
</connections> | ||
<point key="canvasLocation" x="50" y="97"/> | ||
</tableViewCell> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// DemoTableViewController.h | ||
// Demo | ||
// | ||
// Created by Leo on 2018/11/18. | ||
// Copyright © 2018 Leo Huang. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface DemoTableViewController : UITableViewController | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// DemoTableViewController.m | ||
// Demo | ||
// | ||
// Created by Leo on 2018/11/18. | ||
// Copyright © 2018 Leo Huang. All rights reserved. | ||
// | ||
|
||
#import "DemoTableViewController.h" | ||
#import "DemoTableViewCell.h" | ||
|
||
@interface DemoTableViewController () | ||
|
||
@end | ||
|
||
@implementation DemoTableViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
[self.tableView registerNib:[UINib nibWithNibName:@"DemoTableViewCell" bundle:nil] | ||
forCellReuseIdentifier:@"cell"]; | ||
//弱持有Self,因为self持有EventBus,EventBus持有block | ||
__weak typeof(self) weakSelf = self; | ||
|
||
//Cell中Button1点击,采用String来唯一区分 | ||
[[self subscribeName:Button1ClickedEvent on:self.eventDispatcher] | ||
next:^(NSString *event) { | ||
NSLog(@"Button 1 clicked"); | ||
}]; | ||
|
||
//Cell中Button2点击,采用类来区分 | ||
[[self subscribe:Button2ClickEvent.class on:self.eventDispatcher] | ||
next:^(Button2ClickEvent * event) { | ||
NSIndexPath * indexPath = [weakSelf.tableView indexPathForCell:event.cell]; | ||
NSLog(@"Button 2 in cell %ld clicked",(long)indexPath.row); | ||
}]; | ||
} | ||
|
||
#pragma mark - Table view data source | ||
|
||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | ||
return 1; | ||
} | ||
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | ||
return 10; | ||
} | ||
|
||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | ||
DemoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; | ||
cell.indexLabel.text = @(indexPath.row).stringValue; | ||
return cell; | ||
} | ||
|
||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ | ||
return 50.0; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.