Skip to content

Commit dca77d6

Browse files
committed
Added section deletion in the Testing_Example.
1 parent 186316e commit dca77d6

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

Example/Testing_Example/FZAccordionTableViewExample/AccordionHeaderView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ static NSString *const kAccordionHeaderViewReuseIdentifier = @"AccordionHeaderVi
1313

1414
@interface AccordionHeaderView : FZAccordionTableViewHeaderView
1515

16+
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;
17+
1618
@end

Example/Testing_Example/FZAccordionTableViewExample/AccordionHeaderView.xib

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
66
</dependencies>
77
<objects>
88
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -15,7 +15,7 @@
1515
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
1616
<subviews>
1717
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Header" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="529-R1-yiG">
18-
<rect key="frame" x="266" y="10" width="67" height="24"/>
18+
<rect key="frame" x="264.5" y="10" width="70.5" height="24"/>
1919
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
2020
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
2121
<nil key="highlightedColor"/>
@@ -27,6 +27,12 @@
2727
<constraint firstAttribute="height" constant="1" id="Dgq-16-x6W"/>
2828
</constraints>
2929
</view>
30+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Wbo-4f-nBI">
31+
<rect key="frame" x="545" y="7" width="45" height="30"/>
32+
<state key="normal" title="Delete">
33+
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
34+
</state>
35+
</button>
3036
</subviews>
3137
<color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
3238
<constraints>
@@ -35,6 +41,8 @@
3541
<constraint firstAttribute="centerX" secondItem="529-R1-yiG" secondAttribute="centerX" constant="0.5" id="Ez4-cT-XW6"/>
3642
<constraint firstItem="Etg-G3-Srz" firstAttribute="leading" secondItem="Y9z-3k-J3L" secondAttribute="leading" id="diQ-O1-FHr"/>
3743
<constraint firstAttribute="bottom" secondItem="Etg-G3-Srz" secondAttribute="bottom" id="gpa-Wo-lfq"/>
44+
<constraint firstItem="Wbo-4f-nBI" firstAttribute="centerY" secondItem="Y9z-3k-J3L" secondAttribute="centerY" id="iaE-QE-1Hx"/>
45+
<constraint firstAttribute="trailing" secondItem="Wbo-4f-nBI" secondAttribute="trailing" constant="10" id="sCX-4g-9Fj"/>
3846
</constraints>
3947
</view>
4048
</subviews>
@@ -46,6 +54,9 @@
4654
</constraints>
4755
<nil key="simulatedStatusBarMetrics"/>
4856
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
57+
<connections>
58+
<outlet property="deleteButton" destination="Wbo-4f-nBI" id="kmg-4A-PJh"/>
59+
</connections>
4960
</view>
5061
</objects>
5162
</document>

Example/Testing_Example/FZAccordionTableViewExample/FirstViewController.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ - (void)setupTableView {
4545
[self.tableView registerNib:[UINib nibWithNibName:@"AccordionHeaderView" bundle:nil] forHeaderFooterViewReuseIdentifier:kAccordionHeaderViewReuseIdentifier];
4646
}
4747

48+
#pragma mark - Action -
49+
50+
- (IBAction)pressedDeleteButton:(UIButton *)sender {
51+
// Don't use tag in real code
52+
[self.sections removeObjectAtIndex:sender.tag];
53+
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
54+
}
55+
4856
#pragma mark - Class Overrides -
4957

5058
- (BOOL)prefersStatusBarHidden {
@@ -80,11 +88,15 @@ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:
8088
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
8189
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCellReuseIdentifier forIndexPath:indexPath];
8290
cell.textLabel.text = @"Cell";
91+
8392
return cell;
8493
}
8594

8695
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
87-
return [tableView dequeueReusableHeaderFooterViewWithIdentifier:kAccordionHeaderViewReuseIdentifier];
96+
AccordionHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kAccordionHeaderViewReuseIdentifier];
97+
headerView.deleteButton.tag = section; // This is bad code, but works for testing!
98+
[headerView.deleteButton addTarget:self action:@selector(pressedDeleteButton:) forControlEvents:UIControlEventTouchUpInside];
99+
return headerView;
88100
}
89101

90102
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

0 commit comments

Comments
 (0)