मैं: 100 पंक्ति समाप्त होने पर, इस पंक्ति पर सेल हो और firstResponder के टैग के साथ सेल सामग्री दृश्य = 1 बनाने के लिए स्क्रॉल इसे एक पुरानी पोस्ट का एहसास है, लेकिन मुझे एक ही समस्या थी और एक समाधान बनाया जो मेरे लिए अच्छा काम करता था। मैंने ब्लॉक के साथ UIAlertViews बनाने के लिए NSCookBook पर उपयोग की जाने वाली तकनीकों को लागू किया। इसके कारण मैं गया क्योंकि मैं UIView के + एनिमेट के बजाय अंतर्निहित एनिमेशन का उपयोग करना चाहता था: एनिमेशन: समापन:। आईओएस 7 में परिवर्तन के साथ इन एनिमेशन के बीच एक बड़ा अंतर है।
आप UITableView के लिए एक श्रेणी बनाते हैं और कार्यान्वयन फ़ाइल में आप एक आंतरिक निजी वर्ग बनाते हैं जो ब्लॉक को कॉलबैक के प्रतिनिधि के रूप में निर्दिष्ट करके कॉलबैक करेगा। पकड़ यह है कि जब तक ब्लॉक को बुलाया जाता है, तो मूल प्रतिनिधि "बोलने" के लिए बोल जाएगा, क्योंकि नया प्रतिनिधि वह वस्तु है जो ब्लॉक को कॉल करेगा। यही कारण है कि जब मैंने ब्लॉक को मूल UITableViewDelegate को पुन: असाइन करने के लिए बुलाया था तो संदेश भेजने के लिए एक अधिसूचना दी गई। इस कोड का परीक्षण किया गया है और मेरे अंत में काम कर रहा है।
// Header file
@interface UITableView (ScrollDelegateBlock)
-(void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
atScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated
scrollFinished:(void (^)())scrollFinished;
@end
// Implementation file
#import "UITableView+ScrollDelegateBlock.h"
#import <objc/runtime.h>
NSString *const BLOCK_CALLED_NOTIFICATION = @"BlockCalled";
@interface ScrollDelegateWrapper : NSObject <UITableViewDelegate>
@property (copy) void(^scrollFinishedBlock)();
@end
@implementation ScrollDelegateWrapper
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
if (self.scrollFinishedBlock) {
[[NSNotificationCenter defaultCenter] postNotificationName:BLOCK_CALLED_NOTIFICATION object:nil];
self.scrollFinishedBlock();
}
}
@end
static const char kScrollDelegateWrapper;
static id<UITableViewDelegate>previousDelegate;
@implementation UITableView (ScrollDelegateBlock)
-(void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
atScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated
scrollFinished:(void (^)())scrollFinished {
previousDelegate = self.delegate;
ScrollDelegateWrapper *scrollDelegateWrapper = [[ScrollDelegateWrapper alloc] init];
scrollDelegateWrapper.scrollFinishedBlock = scrollFinished;
self.delegate = scrollDelegateWrapper;
objc_setAssociatedObject(self, &kScrollDelegateWrapper, scrollDelegateWrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(blockCalled:)
name:BLOCK_CALLED_NOTIFICATION
object:nil];
}
/*
* Assigns delegate back to the original delegate
*/
-(void) blockCalled:(NSNotification *)notification {
self.delegate = previousDelegate;
[[NSNotificationCenter defaultCenter] removeObserver:self
name:BLOCK_CALLED_NOTIFICATION
object:nil];
}
@end
फिर आप एक ब्लॉक के साथ किसी भी अन्य की तरह विधि कॉल कर सकते हैं:
[self.tableView scrollToRowAtIndexPath:self.currentPath
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES
scrollFinished:^{
NSLog(@"scrollFinished");
}
];
कैसे आप अपने 'myAnimation' सूचक initialising कर रहे हैं? –