Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
An implementation of Swift Example
Browse files Browse the repository at this point in the history
- Implement MessageViewController (Swift)
- Fix a bug that UILongPressGestureRecognizer is added multiple times
(ObjC)
- Fix a bug that Attempt to present UIAlertController on
UINavigationController which is already presenting UIAlertController
(ObjC)
  • Loading branch information
WEI-JEN TU committed Mar 16, 2016
1 parent 7785f10 commit 0078f39
Show file tree
Hide file tree
Showing 4 changed files with 685 additions and 26 deletions.
9 changes: 8 additions & 1 deletion Examples/Messenger-Shared/Bridge-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "SLKTextViewController.h"
#import <SLKTextViewController.h>

#import "Message.h"
#import "MessageTableViewCell.h"
#import "MessageTextView.h"
#import "TypingIndicatorView.h"

#import <LoremIpsum/LoremIpsum.h>
40 changes: 21 additions & 19 deletions Examples/Messenger-Shared/MessageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,29 @@ - (void)simulateUserTyping:(id)sender

- (void)didLongPressCell:(UIGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateEnded) {
#ifdef __IPHONE_8_0
if (SLK_IS_IOS8_AND_HIGHER && [UIAlertController class]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
alertController.modalPresentationStyle = UIModalPresentationPopover;
alertController.popoverPresentationController.sourceView = gesture.view.superview;
alertController.popoverPresentationController.sourceRect = gesture.view.frame;

[alertController addAction:[UIAlertAction actionWithTitle:@"Edit Message" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
if (SLK_IS_IOS8_AND_HIGHER && [UIAlertController class]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
alertController.modalPresentationStyle = UIModalPresentationPopover;
alertController.popoverPresentationController.sourceView = gesture.view.superview;
alertController.popoverPresentationController.sourceRect = gesture.view.frame;

[alertController addAction:[UIAlertAction actionWithTitle:@"Edit Message" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self editCellMessage:gesture];
}]];

[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]];

[self.navigationController presentViewController:alertController animated:YES completion:nil];
}
else {
[self editCellMessage:gesture];
}]];

[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]];

[self.navigationController presentViewController:alertController animated:YES completion:nil];
}
else {
[self editCellMessage:gesture];
}
}
#else
[self editCellMessage:gesture];
[self editCellMessage:gesture];
#endif
}
}

- (void)editCellMessage:(UIGestureRecognizer *)gesture
Expand Down Expand Up @@ -572,11 +574,11 @@ - (MessageTableViewCell *)messageCellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MessageTableViewCell *cell = (MessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:MessengerCellIdentifier];

if (!cell.textLabel.text) {
if (cell.gestureRecognizers.count == 0) {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPressCell:)];
[cell addGestureRecognizer:longPress];
}

Message *message = self.messages[indexPath.row];

cell.titleLabel.text = message.username;
Expand Down
Loading

0 comments on commit 0078f39

Please sign in to comment.