Skip to content

Commit 34ef6a9

Browse files
committed
fixed possible crash with indexing of instructions; added logic to scroll to top when picking arch;
1 parent 87b2a50 commit 34ef6a9

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

ARMRef/ARMRef/Source/Architecture/AArchitectureViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
7575

7676
if (![self.loader.architecture isEqualToString:arch]) {
7777
BlockSafetyCallWithArgs(self.pickCompletion, arch);
78+
7879
[self.loader loadArchitecture:arch];
7980
}
8081

ARMRef/ARMRef/Source/CollectionView/ACollectionViewDataHandle.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ @implementation ACollectionViewDataHandle
3636

3737
- (nonnull __kindof UICollectionViewCell *) collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
3838
ACollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ACollectionViewCell.identifier forIndexPath:indexPath];
39-
cell.instruction = self.instructions[indexPath.row];
39+
cell.instruction = safetyObjectAtIndex(self.instructions, indexPath.row);
4040

4141
return cell;
4242
}
@@ -65,7 +65,7 @@ - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIn
6565

6666
- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
6767
ACollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ACollectionViewCell.identifier forIndexPath:indexPath];
68-
cell.instruction = self.instructions[indexPath.row];
68+
cell.instruction = safetyObjectAtIndex(self.instructions, indexPath.row);
6969

7070
CGFloat maxSize = [cell maxSizeForInstruction:self.instructions[indexPath.row] withWidth:collectionView.bounds.size.width - 20.0f];
7171

ARMRef/ARMRef/Source/Defines.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@
4848
#define BlockSafetyCallWithArgs(block, ...) \
4949
if (block) block(__VA_ARGS__)
5050

51+
// Array
52+
#define safetyObjectAtIndex(array, index) \
53+
(array.count > index ? array[index] : nil)
54+
55+
#define safetyPointerObjectAtIndex(array, index) \
56+
(array.count > index ? [array pointerAtIndex:index] : nil)
57+
58+
5159
#endif /* Defines_h */

ARMRef/ARMRef/Source/Main/AMainViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ - (void) _changeArch:(UIBarButtonItem *)item {
104104
strongify(self);
105105

106106
[self _showNoDataStyle:YES];
107+
[self.collectionView setContentOffset:CGPointZero animated:NO];
107108
};
108109

109110
[self.navigationController pushViewController:viewController animated:YES];

0 commit comments

Comments
 (0)