मैं इसUIMenuController विधि setTargetRect: ध्यान में रखते हुए: UITableView
की तरह मेरे tableview
में कस्टम UIMenuController
प्रदर्शित कर रहा हूँ, लेकिन मुद्दा यह है कि यह केंद्र में प्रदर्शित कर रहा है है में काम नहीं कर रहा के शीर्ष पर प्रदर्शित करना चाहते हैं label
जो नारंगी रंग है। label
के शीर्ष पर प्रदर्शित करने के लिए मैंने यह [menu setTargetRect:CGRectMake(10, 10, 0, 0) inView:self.lbl];
नीचे दिया है पूरा कोड है।
लेकिन यदि मैं UIMenuController
UITableView
setTargetRect
के बिना ठीक काम करता हूं तो मैं ठीक काम करता हूं।
setTargetRect
UITableView
के साथ क्यों काम नहीं कर रहा है?
setTargetRect डॉक्टर का कहना है:
(क) यह लक्ष्य आयत (targetRect) आम तौर पर एक चयन के सीमांकन आयत है। UIMenuController इस आयताकार के ऊपर संपादन मेनू को स्थान देता है; यदि वहां मेनू के लिए पर्याप्त जगह नहीं है, तो यह आयताकार के नीचे स्थित है। मेनू के सूचक को उचित आयत के शीर्ष या नीचे के केंद्र पर रखा गया है।
(ख) ध्यान दें कि यदि आप चौड़ाई या लक्ष्य आयत शून्य की ऊंचाई बनाने, UIMenuController एक पंक्ति या स्थिति के लिए बिंदु के रूप में लक्षित क्षेत्र व्यवहार करता है (उदाहरण के लिए, एक प्रविष्टि कैरट या एक बिंदु)।
(सी) एक बार यह सेट हो जाने के बाद, लक्ष्य आयताकार दृश्य को ट्रैक नहीं करता है; यदि दृश्यों को देखें (जैसे स्क्रॉल व्यू में होगा), तो आपको तदनुसार लक्ष्य आयताकार अपडेट करना होगा।
मुझे क्या याद आ रही है?
MyViewController
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TheCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cid" forIndexPath:indexPath];
cell.lbl.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
return YES;
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
// required
}
MyCustomCell
- (void)awakeFromNib {
// Initialization code
UIMenuItem *testMenuItem = [[UIMenuItem alloc] initWithTitle:@"Test" action:@selector(test:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems: @[testMenuItem]];
[menu setTargetRect:CGRectMake(10, 10, 0, 0) inView:self.lbl];
[menu update];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(BOOL) canPerformAction:(SEL)action withSender:(id)sender {
return (action == @selector(copy:) || action == @selector(test:));
}
/// this methods will be called for the cell menu items
-(void) test: (id) sender {
NSLog(@"test");
}
-(void) copy:(id)sender {
UIMenuController *m = sender;
NSLog(@"copy");
}
साथ मैं यकीन है कि जब से तुम है कि आप 'shouldShowMenuForRowAtIndexPath' के लिए नहीं लौटना चाहिए एक कस्टम रेक्ट उपयोग करने के लिए कोशिश कर रहे हैं रहा हूँ, जो भी होगा 'canPerformAction' और 'performAction' विधियों को अनावश्यक भी बनाएं। –
मेरी एकमात्र अन्य चिंता यह है कि जब आप 'UIMenuController' को कॉन्फ़िगर करते हैं तो लेबल दृश्य पदानुक्रम में डाला नहीं गया होता, जो कि एक समस्या हो सकती है। आपको _may_ को 'UIMenuController' कॉन्फ़िगरेशन कोड को' tableView: willDisplayCell', या यहां तक कि सेल की 'UIView' विधि' में भी 'UMenToSuperview'] (https://developer.apple.com/) में एक अलग प्रतिनिधि विधि में स्थानांतरित करने की आवश्यकता है। लाइब्रेरी/आईओएस/प्रलेखन/UIKit/संदर्भ/UIView_Class/index.html # // apple_ref/occ/instm/UIView/didMoveToSuperview) यह सुनिश्चित करने के लिए कि सेल आपके कस्टम रीक्ट सेट करने से पहले स्क्रीन पर वास्तव में स्क्रीन पर है। –
@ सांताक्लॉस नहीं कुछ भी काम नहीं कर रहा है, मेरा मेनू अभी भी केंद्र में दिखाई दे रहा है। –